Questions tagged [forloop]

For loop is a statement executing some code repeatedly (forever or till some condition exists it)

Filter by
Sorted by
Tagged with
2
votes
2answers
451 views

Using a loop in a loop, how do I check if child loop is empty to not display parent loop?

I'm trying to display a list of names alphabetically ordered. This is working fine, but I also want to check if the name is intoCollection or not (using a Lightswitch). If it is intoCollection, it ...
2
votes
1answer
1k views

How do I create a list of categories and display the entries relating to each of these categories that have at least one entry?

Here's a summary of what I try to do: I created a Single page with a specific template where I want to display a list of partners I created a group of Categories to define all types of partners All ...
8
votes
4answers
5k views

Remove the last comma in an inline list of tags?

In a list of tags I'd like to remove the last comma. So is there something that works like the Ee backspace parameter?
4
votes
2answers
660 views

Fetch Single asset without for loop?

I've got a Assets field which is limited to 1 asset inside a Matrix field. Is there a better way to fetch the image without using a forloop? At the minute I've got: {% for image in block....
4
votes
1answer
378 views

How can I iterate more than 100 blocks in a matrix field for loop?

I am looping through a matrix field and it appears to stop looping when the index reaches 100 but I have more than 100 blocks here. How can I loop through the remaining blocks? {% for block in entry....
8
votes
1answer
2k views

How do you filter matrix blocks by type?

Is there a way to filter a matrix by block type, or get a count of how many items there are of a certain type? Can't find a syntax example. I created a matrix with two blocks. In pseudo code, ...
6
votes
1answer
1k views

How do you return a message if no entries are found?

I thought this would be very easy but I'm having a hard time figuring it out. How do you output a warning/message if there are no entries to loop through? {% set entries = craft.entries.section('...
9
votes
2answers
11k views

Is it possible to break out of a loop in twig?

Is it possible to break out of a loop in twig? If it is, how would I do it?
3
votes
1answer
3k views

How do I loop through entries for a specific entry type?

I would like to loop through entries in a channel but only the ones for a specific entry type. Is this Possible? I'm using the free version of craft on a test site, I have used the channel for my ...
5
votes
2answers
3k views

How to correctly output a Table Field?

I have set up a Matrix field with three blocks, each contains a Table field. Each table has one column - a single line text field. When I call these tables into the template with this code, each row ...
4
votes
1answer
1k views

How to create new variable from For Loop results

I need to get a list of all the "sizes" from my Table type field column. The list of sizes needs to be separated by a "|"... eg: small|medium|large My Table type field name is "productAttributes" and ...