Forums / Setup & design / Convert {section} to {foreach}
Softriva .com
Tuesday 22 August 2006 1:46:08 am
I am trying to get rid of {let} and {section} and use {def} and {foreach}. Would you please tell me what is wrong with code conversion? My code does not produce anything
Original Code
{let use_url_translation=ezini('URLTranslator','Translation')|eq('enabled')} {section show=$search_result} <table class="list" width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <th>{"Name"|i18n("design/standard/content/search")}</th> <th width="1">{"Class"|i18n("design/standard/content/search")}</th> </tr> <tr> {section name=SearchResult loop=$search_result show=$search_result sequence=array(bglight,bgdark)} {node_view_gui view=search sequence=$:sequence use_url_translation=$use_url_translation content_node=$:item} {delimiter modulo=1} </tr> <tr> {/delimiter} {section-else} {/section} </tr> </table> {/section} {/let}
My Code
{def use_url_translation=ezini('URLTranslator','Translation')|eq('enabled')} {if $search_result} <table class="list" width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <th>{"Name"|i18n("design/standard/content/search")}</th> <th width="1">{"Class"|i18n("design/standard/content/search")}</th> </tr> <tr> {foreach $search_result as $SearchResultIndex=>$SearchResult sequence=array(bglight,bgdark) as $seq} {node_view_gui content_node=$SearchResultIndex.name|wash view=search use_url_translation=$use_url_translation } {delimiter} </tr> <tr> {/delimiter} {/foreach} </tr> </table> {/if} {undef}
Tuesday 22 August 2006 2:14:42 am
Thank you all. I figured out where is my problem:
My New Code
{node_view_gui content_node=$SearchResult view=search use_url_translation=$use_url_translation }
My Old Code
{node_view_gui content_node=$SearchResultIndex.name|wash view=search use_url_translation=$use_url_translation }
Pascal von Büren
Tuesday 22 August 2006 2:40:01 am
I guess, you should also change you first line:
{def use_url_translation=ezini('URLTranslator','Translation')|eq('enabled')}
should look like
{def $use_url_translation=ezini('URLTranslator','Translation')|eq('enabled')}
as you can see here: http://ez.no/doc/ez_publish/technical_manual/3_8/reference/template_functions/variables/def
The defined variable must have the $-Sign.
Marcin Drozd
Tuesday 22 August 2006 3:03:21 am
HiIm not sure but Claudia said: <i>there should be no equal sign between the words sequence and array.</i> ( http://ez.no/community/forum/developer/i_can_t_use_user_parameters_on_templates/re_i_can_t_use_user_parameters_on_templates )
and example3 on the http://ez.no/doc/ez_publish/technical_manual/3_8/reference/template_control_structures/looping/foreach
http://ez-publish.pl
Tuesday 22 August 2006 4:19:35 am
Thanks Pascal
I added the $ sign.
Thanks Marcin,
Now, I know why sequence wasn't working ok. I removed the = sign and everything worked ok.
OOzy