This site has been archived and you can no longer log in or post new messages. For up-to-date community resources please visit

eZ Community » Forums » Developer » Limit nuber of tags from list

Limit nuber of tags from list

Limit nuber of tags from list

Wednesday 03 July 2013 9:39:32 am - 6 replies

Hey everyone!

I was using this line of code for calling all tags.

  {foreach ezkeywordlist(    'blog_post', $blog_node.node_id ) as $keyword}
   <li><a href={concat( $blog_node.url_alias, "/(tag)/", $keyword.keyword|rawurlencode )|ezurl} title="{$keyword.keyword}">{$keyword.keyword}</a></li>

But now there is more than 100 tags, so i don't want to list all of them. How to change code to limit tags for only 5-6 tags (or to put max value of 5-6 tags to be shown).

Thanks in advance!

Wednesday 03 July 2013 1:08:22 pm


while ezkeywordlist operator does not support limiting the output to certain number of tags, you can always write {for} loop instead of {foreach}, something like this:

{def $keyword_list = ezkeywordlist( 'blog_post', $blog_node.node_id )}
{for 0 to 5 as $counter}
    <li><a href={concat( $blog_node.url_alias, "/(tag)/", $keyword_list[$counter].keyword|rawurlencode )|ezurl} title="{$keyword_list[$counter].keyword}">{$keyword_list[$counter].keyword}</a></li>

Wednesday 03 July 2013 3:37:16 pm

Thanks a lot for reply!

This works like i wanted. Thanks a lot for a help!

I just wondering is there some additional command for random tags?

Thanks a lot again!


Wednesday 03 July 2013 4:03:17 pm


I think there's no feature to fetch random tags unfortunatelly.

P.S. You should use wash() operator to output keywords to HTML to protect from XSS attacks.

So instead of:


you should use:


Modified on Wednesday 03 July 2013 4:05:34 pm by Edi Modrić

Thursday 04 July 2013 9:04:09 am

I change this one.

Thanks again for help, i really appreciate!

Thursday 04 July 2013 8:13:31 pm

Instead of a for loop, I would use the max parameter in your foreach, something like:

 {foreach ezkeywordlist( 'blog_post', $blog_node.node_id ) as $keyword max 5}...{/foreach}

This makes the code cleaner, and avoids off-by-one problems. In general I try to use foreach for all my loops.

Friday 05 July 2013 10:15:39 am

Good one Arne happy.gif Emoticon

I've completely forgotten about max parameter happy.gif Emoticon


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

36 542 Users on board!

Forums menu

Proudly Developed with from