Syntax for foreach with break

Syntax for foreach with break

Friday 03 June 2011 3:44:46 pm - 3 replies

Author Message

Steven E. Bailey

Saturday 04 June 2011 3:23:05 pm

Not exactly what you are looking for but it does use a break:

{if $this_node.data_map.image.content.is_valid}
    {*has an image in the image attribute*}
    <img src={$this_node.data_map.image.content.['medium'].url|ezroot} />
{elseif ne($this_node.object.related_contentobject_count,0)}
    {foreach $this_node.object.related_contentobject_array as $related_object}
        {if eq($related_object.class_identifier,"image")}
            {*has an image as a related object*}
            <img src={$related_object.data_map.image.content.['medium'].url|ezroot} />
            {break}
       {/if}
    {/foreach}
{else}
    {*got bubkis*}
    <img src={"dummy.jpg"|ezimage}>
{/if}

Certified eZPublish developer
http://ez.no/certification/verify/396111

Available for ezpublish troubleshooting, hosting and custom extension development: http://www.leidentech.com

Jérôme Vieilledent

Sunday 05 June 2011 3:47:05 am

Hi Paul

You can use the {break} command for that, as suggested in Steven's snippet.

Take a look at the foreach reference doc for more info ;-).

paul bolger

Sunday 05 June 2011 5:01:47 am

Thanks Steven, That works well and was what I was looking for. Thanks too Jérôme. The documentation is a bit vague about how to use {break}, but now I understand. If only I could add a comment to the documentation so others could see what I've been shown... 

Paul Bolger

You must be logged in to post messages in this topic!

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