Cataloger: need help with coding an array/if statement

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
kirks
Forum Members
Forum Members
Posts: 14
Joined: Tue Aug 02, 2011 11:47 pm

Cataloger: need help with coding an array/if statement

Post by kirks »

I'm not a programmer although I've had some exposure to basic code years ago. I'm really loving CMSms and Cataloger and the power they give me as non-programmer with years of HTML, CSS and Photoshop experience.

My question is how to code an array and if statement using Cataloger to display 20 user-defined attribute fields as follows: option01 - option10 and option01price - option10price.

Here's the code I have so far.

Code: Select all

<div class="catalog_item">
</div>

<table class="product_text_table" border="0" cellpadding="0" cellspacing="0">
  <tr><td colspan="2" class="product_text_small">Model Number: {$modelnumber}</td></tr>
  <tr><td colspan="2" class="product_text_large">{$title}</td></tr>
  <tr><td colspan="2" class="product_price_wide">${$price}</td></tr>
  {section name=at loop=$attrlist} (array code with if statement to display only option attributes with data)
  <tr>
    <td class="product_label">{option[?]}:</td>
    <td class="product_price">$[option[?]price</td>
  </tr>
  {/section}
  <tr><td colspan="2" class="product_footnote">{$footnote}</td></tr>
</table>
When completed it should output something like this: http://www.unclaimedfreight.biz/our_pro ... uct_id=616

There's plenty of documentation on php arrays and if statements but I'm not sure how that works with CMSms's Smarty Tags and the fact that this project is well overdue, I don't have time to try to learn it right now.
Any help would be appreciated.
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1978
Joined: Mon Jan 29, 2007 4:47 pm

Re: Cataloger: need help with coding an array/if statement

Post by Jo Morg »

I'm not sure I understand you correctly...
On each template you have a list of available smarty vars corresponding to each and every user-defined attribute field, as long as previously defined. These can be found under Item Template Variables, right below the template edit text area.
That allows you to make custom templates for any of the content types cataloger has to offer without the need to work with arrays. Just use the attributes aliases and look at the samples and help of the module. If I misunderstood your question, please give a more detailed description of what you want to accomplish and how.
HTH
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
kirks
Forum Members
Forum Members
Posts: 14
Joined: Tue Aug 02, 2011 11:47 pm

Re: Cataloger: need help with coding an array/if statement

Post by kirks »

Jo Morg wrote:I'm not sure I understand you correctly...
On each template you have a list of available smarty vars corresponding to each and every user-defined attribute field, as long as previously defined. These can be found under Item Template Variables, right below the template edit text area.
That allows you to make custom templates for any of the content types cataloger has to offer without the need to work with arrays. Just use the attributes aliases and look at the samples and help of the module. If I misunderstood your question, please give a more detailed description of what you want to accomplish and how.
HTH
Okay, I want the option01 through option10 to appear in a new table row/cell only if there is data. I don't want to have to do the following:

Code: Select all

<table class="product_text_table" border="0" cellpadding="0" cellspacing="0">
  <tr><td colspan="2" class="product_text_small">Model Number: {$modelnumber}</td></tr>
  <tr><td colspan="2" class="product_text_large">{$title}</td></tr>
  <tr><td colspan="2" class="product_price_wide">${$price}</td></tr>
{if $option01 > ""}
  <tr>
    <td class="product_label">{$option01}:</td>
    <td class="product_price">${$option01price}</td>
  </tr>
{/if}
{if $option02 > ""}
  <tr>
    <td class="product_label">{$option02}:</td>
    <td class="product_price">${$option02price}</td>
  </tr>
{/if}
{if $option03 > ""}
  <tr>
    <td class="product_label">{$option03}:</td>
    <td class="product_price">${$option03price}</td>
  </tr>
{/if}
{if $option04 > ""}
  <tr>
    <td class="product_label">{$option04}:</td>
    <td class="product_price">${$option04price}</td>
  </tr>
{/if}
{if $option05 > ""}
  <tr>
    <td class="product_label">{$option05}:</td>
    <td class="product_price">${$option05price}</td>
  </tr>
{/if}
{if $option06 > ""}
  <tr>
    <td class="product_label">{$option06}:</td>
    <td class="product_price">${$option06price}</td>
  </tr>
{/if}
{if $option07 > ""}
  <tr>
    <td class="product_label">{$option07}:</td>
    <td class="product_price">${$option07price}</td>
  </tr>
{/if}
{if $option08 > ""}
  <tr>
    <td class="product_label">{$option08}:</td>
    <td class="product_price">${$option08price}</td>
  </tr>
{/if}
{if $option09 > ""}
  <tr>
    <td class="product_label">{$option09}:</td>
    <td class="product_price">${$option09price}</td>
  </tr>
{/if}
{if $option10 > ""}
  <tr>
    <td class="product_label">{$option10}:</td>
    <td class="product_price">${$option10price}</td>
  </tr>
{/if}

  <tr><td colspan="2" class="product_footnote">{$footnote}</td></tr>
</table>

I hope that makes sense. Thanks for your reply! :)
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1978
Joined: Mon Jan 29, 2007 4:47 pm

Re: Cataloger: need help with coding an array/if statement

Post by Jo Morg »

With Smarty 3 you should be able to do something like this (untested):

Code: Select all

<table class="product_text_table" border="0" cellpadding="0" cellspacing="0">
  <tr><td colspan="2" class="product_text_small">Model Number: {$modelnumber}</td></tr>
  <tr><td colspan="2" class="product_text_large">{$title}</td></tr>
  <tr><td colspan="2" class="product_price_wide">${$price}</td></tr>
  {section name=at loop=20}
{if isset(option{$smarty.section.at.index})}
  <tr>
    <td class="product_label">{option{$smarty.section.at.index}}:</td>

    <td class="product_price">${option{$smarty.section.at.index}price}</td>
  </tr>
{/if}
{/section}
  <tr><td colspan="2" class="product_footnote">{$footnote}</td></tr>
</table>
HTH
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
kirks
Forum Members
Forum Members
Posts: 14
Joined: Tue Aug 02, 2011 11:47 pm

Re: Cataloger: need help with coding an array/if statement

Post by kirks »

Thanks. There are errors but I may be able to figure it out.

My biggest question is, are there any detailed documentation with examples? For instance, I want to have a list page that contains Categories, sub-categories and items within the sub-categories.

The module says it's possible but doesn't provide any examples of how to code it.
Post Reply

Return to “Modules/Add-Ons”