Forums / Setup & design / Convert {section} to {foreach}

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

eZ debug

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

Main resources:

Total runtime0.1646 sec
Peak memory usage2,048.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0061 589.3281180.8359
Module start 'content' 0.00610.0046 770.164197.9922
Module end 'content' 0.01070.1537 868.1563527.8047
Script end 0.1644  1,395.9609 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00331.9841200.0002
Check MTime0.00130.7889200.0001
Mysql Total
Database connection0.00090.550010.0009
Mysqli_queries0.114269.42391410.0008
Looping result0.00140.82521390.0000
Template Total0.153493.210.1534
Template load0.00080.497710.0008
Template processing0.152692.740810.1526
Override
Cache load0.00060.342110.0006
Sytem overhead
Fetch class attribute can translate value0.00110.648910.0011
XML
Image XML parsing0.00040.252810.0004
General
dbfile0.00855.1373200.0004
String conversion0.00000.004230.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

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

Time used to render debug report: 0.0002 secs