Jump to content

Latte: Create a comma separated list of items


Recommended Posts

I am as many others love ❤️the Latte template engine, and I use RockFrontend to integrate it into ProcessWire.

One cool feature of Latte is, that you can easily create a comma-separated (or any other separator) list of items, where the last item does not have a separator (comma) afterwards, without needing PHP.

Take this code as an example

{foreach $pages->get('/myparentpage')->children as $item}
	{$item->title|noescape}{sep}, {/sep}

Which will output a list like: first title, second title, third title

If you want to know more use cases take a look at the documentation at https://latte.nette.org/en/tags#toc-first-last-sep

  • Like 5
Link to comment
Share on other sites

I think you can do shorter. 🙂 With Twig I would do that:

{{ pages.get('/').children.each('title') | join(', ') }}


But usually I use html lists so WireArray API is enough:

<ul>{{ pages.get('/').children.each('<li>{title}</li>') }}</ul>


  • Like 2
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...