MichaelMcG Posted August 29, 2011 Share Posted August 29, 2011 Hi, I'd like to cancel my foreach loop after the first loop: {foreach from=$entries item=entry} <li><a class="bloglink" {if $rewrite==1}href="{$content_dir}blog/entry/{$entry.id_entry}-{$entry.link}"{else}href="{$content_dir}modules/blog/index.php?entry={$entry.id_entry}"{/if}>{$entry.title|escape|truncate:30}</a><br />{$entry.entry|truncate:130}</li> {/foreach} How do I achieve this? Thank you. Link to comment Share on other sites More sharing options...
MichaelMcG Posted August 29, 2011 Author Share Posted August 29, 2011 Hi, I'd like to cancel my foreach loop after the first loop: {foreach from=$entries item=entry} <li><a class="bloglink" {if $rewrite==1}href="{$content_dir}blog/entry/{$entry.id_entry}-{$entry.link}"{else}href="{$content_dir}modules/blog/index.php?entry={$entry.id_entry}"{/if}>{$entry.title|escape|truncate:30}</a><br />{$entry.entry|truncate:130}</li> {/foreach} How do I achieve this? Thank you. I'm assuming in the {foreach} loop I'd do something like: i = 0; i++; // show contents if {$i=1} break; but I'm not sure how to achieve this with PrestaShop. Thanks for any help. Link to comment Share on other sites More sharing options...
shokinro Posted August 29, 2011 Share Posted August 29, 2011 please try this (assume you want execute only one time. {foreach from=$entries item=entry name=foo} {if $smarty.foreach.foo.index == 1} {break}{/if} <li><a class="bloglink" {if $rewrite==1}href="{$content_dir}blog/entry/{$entry.id_entry}-{$entry.link}"{else}href="{$content_dir}modules/blog/index.php?entry={$entry.id_entry}"{/if}>{$entry.title|escape|truncate:30}</a><br />{$entry.entry|truncate:130}</li> {/foreach} the above code can used for any number of executions, you can execute 2 time, or 3 times, just changes the number. 1 Link to comment Share on other sites More sharing options...
Patric Posted August 30, 2011 Share Posted August 30, 2011 Topic moved into the "Development" section. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now