Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

Making the Extra Fields Template Smartyier

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 04-25-2003, 06:53 AM
 
machnhed1 machnhed1 is offline
 

eXpert
  
Join Date: Feb 2003
Location: Illinois
Posts: 274
 

Default Making the Extra Fields Template Smartyier

Hi everyone,

I have been wresting with this problem for a day or so and have yet to find the right syntax. Hopefully someone here will show me the light.

Here's the code (it's altered a bit from the original file, but it shouldn't be a problem)...
Code:
{* $Id: product.tpl,v 1.2 2002/04/23 10:38:01 mav Exp $ *} {section name=field loop=$extra_fields} {if $extra_fields[field].active eq "Y"} {assign var="creator" value=$product.param00} <tr><td width=30% valign="top"> {$extra_fields[field].field}</td> <td> {if %field.index% eq 0}{$product.param00}{elseif %field.index% eq 1}{$product.param01}{elseif %field.index% eq 2}{$product.param02}{elseif %field.index% eq 3}{$product.param03}{elseif %field.index% eq 4}{$product.param04}{elseif %field.index% eq 5}{$product.param05}{elseif %field.index% eq 6}{$product.param06}{elseif %field.index% eq 7}{$product.param07}{elseif %field.index% eq 8}{$product.param08}{elseif %field.index% eq 9}{$product.param09}{/if} </td> </tr> {/if} {/section}


What I would like to do is improve the intelligence of the code by adding to the if statement at the top. Right now all the extra product.param fields (00 - 09) print out regardless of whether they have information in them or not. I would like to add to the if statement so that it will only print out the product.param fields that are NOT blank.

I tried altering the if statement with something like this:
Code:
{if $extra_fields[field].active eq "Y" and $product.param.%field.index%|string_format:"%02d" ne ""}

But the syntax is not quite right. I have tried adding backticks, quotes, apostrophes, etc., but nothing has worked yet. I couldnБ─≥t find the answer in the manual, so I hope this board can help.

Thanks in advance for any help provided
__________________
Following the signature guidelines : xcart pro 3.5.8 - [RedHat]
Reply With Quote
  #2  
Old 04-29-2003, 02:10 PM
  kpriest's Avatar 
kpriest kpriest is offline
 

eXpert
  
Join Date: Apr 2003
Location: Seattle, WA
Posts: 263
 

Default

OK - I think I've got it! Maybe not the most efficient way to code it, but best I could do not knowing much PHP or smarty:
Code:
{* $Id: product.tpl,v 1.2 2002/04/23 10:38:01 mav Exp $ *} {section name=field loop=$extra_fields} {if $extra_fields[field].active eq "Y"} <tr><td width=30%> {if %field.index% eq 0 and $product.param00 ne ""}{$extra_fields[field].field} {elseif %field.index% eq 1 and $product.param01 ne ""}{$extra_fields[field].field} {elseif %field.index% eq 2 and $product.param02 ne ""}{$extra_fields[field].field} {elseif %field.index% eq 3 and $product.param03 ne ""}{$extra_fields[field].field} {elseif %field.index% eq 4 and $product.param04 ne ""}{$extra_fields[field].field} {elseif %field.index% eq 5 and $product.param05 ne ""}{$extra_fields[field].field} {elseif %field.index% eq 6 and $product.param06 ne ""}{$extra_fields[field].field} {elseif %field.index% eq 7 and $product.param07 ne ""}{$extra_fields[field].field} {elseif %field.index% eq 8 and $product.param08 ne ""}{$extra_fields[field].field} {elseif %field.index% eq 9 and $product.param09 ne ""}{$extra_fields[field].field} {/if} </td> </td> <td class="ProductPriceSmall"> {if %field.index% eq 0}{$product.param00} {elseif %field.index% eq 1}{$product.param01} {elseif %field.index% eq 2}{$product.param02} {elseif %field.index% eq 3}{$product.param03} {elseif %field.index% eq 4}{$product.param04} {elseif %field.index% eq 5}{$product.param05} {elseif %field.index% eq 6}{$product.param06} {elseif %field.index% eq 7}{$product.param07} {elseif %field.index% eq 8}{$product.param08} {elseif %field.index% eq 9}{$product.param09} {/if} </td> </tr> {/if} {/section}

One problem - the fields are supressed, but the space still seems to be taken up. Is there a smarty {trim} command or something like that??
Reply With Quote
  #3  
Old 04-29-2003, 02:28 PM
 
machnhed1 machnhed1 is offline
 

eXpert
  
Join Date: Feb 2003
Location: Illinois
Posts: 274
 

Default

Definitely a step in the right direction. The html output was a little off, try this code instead.

Code:
{* $Id: product.tpl,v 1.2 2002/04/23 10:38:01 mav Exp $ *} {section name=field loop=$extra_fields} {if $extra_fields[field].active eq "Y"} <tr><td width=30%> {if %field.index% eq 0 and $product.param00 ne ""}{$extra_fields[field].field} {elseif %field.index% eq 1 and $product.param01 ne ""}{$extra_fields[field].field} {elseif %field.index% eq 2 and $product.param02 ne ""}{$extra_fields[field].field} {elseif %field.index% eq 3 and $product.param03 ne ""}{$extra_fields[field].field} {elseif %field.index% eq 4 and $product.param04 ne ""}{$extra_fields[field].field} {elseif %field.index% eq 5 and $product.param05 ne ""}{$extra_fields[field].field} {elseif %field.index% eq 6 and $product.param06 ne ""}{$extra_fields[field].field} {elseif %field.index% eq 7 and $product.param07 ne ""}{$extra_fields[field].field} {elseif %field.index% eq 8 and $product.param08 ne ""}{$extra_fields[field].field} {elseif %field.index% eq 9 and $product.param09 ne ""}{$extra_fields[field].field} {/if} </td> <td class="ProductPriceSmall"> {if %field.index% eq 0}{$product.param00} {elseif %field.index% eq 1}{$product.param01} {elseif %field.index% eq 2}{$product.param02} {elseif %field.index% eq 3}{$product.param03} {elseif %field.index% eq 4}{$product.param04} {elseif %field.index% eq 5}{$product.param05} {elseif %field.index% eq 6}{$product.param06} {elseif %field.index% eq 7}{$product.param07} {elseif %field.index% eq 8}{$product.param08} {elseif %field.index% eq 9}{$product.param09} {/if} </td> </tr> {/if} {/section}

I removed a </td> and
to help with the output. Kudos on the work
__________________
Following the signature guidelines : xcart pro 3.5.8 - [RedHat]
Reply With Quote
  #4  
Old 04-29-2003, 02:39 PM
  kpriest's Avatar 
kpriest kpriest is offline
 

eXpert
  
Join Date: Apr 2003
Location: Seattle, WA
Posts: 263
 

Default

Perfect! Duh - I should've seen the
was in the loop.
This was very productive! Seems like it should be default behavior anyway.

-ken
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 03:52 PM.

   

 
X-Cart forums © 2001-2020