Convert {section} to {foreach}

Author Message

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}

Softriva .com

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

Hi
Im 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

Softriva .com

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

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 20 2025 23:26:17
Script start
Timing: Jan 20 2025 23:26:17
Module start 'layout'
Timing: Jan 20 2025 23:26:17
Module start 'content'
Timing: Jan 20 2025 23:26:17
Module end 'content'
Timing: Jan 20 2025 23:26:17
Script end

Main resources:

Total runtime0.0147 sec
Peak memory usage2,048.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0050 589.0469151.2109
Module start 'layout' 0.00500.0020 740.257836.6484
Module start 'content' 0.00700.0064 776.906394.2656
Module end 'content' 0.01340.0012 871.171933.9922
Script end 0.0146  905.1641 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002215.3062140.0002
Check MTime0.00106.5298140.0001
Mysql Total
Database connection0.00095.978310.0009
Mysqli_queries0.001912.628530.0006
Looping result0.00000.068310.0000
Template Total0.00096.310.0009
Template load0.00074.872110.0007
Template processing0.00021.439710.0002
Override
Cache load0.00053.199810.0005
General
dbfile0.002013.954380.0003
String conversion0.00000.042340.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs