Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [loop]

The tag has no usage guidance.

1
vote
1answer
42 views

Count entries with condition

I would like to count comments that belong to a certain entry (product). I have this so far: {% set comments = craft.entries().section('productcomments').all() %} {% set counter = 0 %} {% for ...
1
vote
2answers
30 views

Possible to paginate product variants in Craft Commerce 2?

I am currently in the process of building a commerce 2 site with a very detailed level of nesting in the product options so we're looking to list all variants for a product. (Sounds silly, but it ...
2
votes
2answers
46 views

Loop index inside a switch content builder

How would one construct this? I have built a little content builder and wish now to change the layout HTML on the fly when there are more than one matrix block. In the example below, this is just one ...
1
vote
1answer
27 views

Batch entries by year?

I have a press release index page that loops through all the press releases. I want to organize them by year. So everything in 2018 will have a header that says 2018 press releases and then all the ...
-1
votes
0answers
37 views

I can access an asset filename, but not its URL

At first I was trying to use the one(), but it always told me the Object of class Craft\ElementCriteriaModel could not be converted to string So searching the documents, I found first(), and that ...
1
vote
1answer
42 views

Entries from matrix should not appear in loop

I have a Matrix with an entry field. I have a Loop which is looping entries out of a section. Goal: The entries from the matrix should not appear in the loop of the section. So the Matrix defines ...
1
vote
1answer
25 views

Loop through all entry types, separate each group type by line rule (hr)

I'm looking for shorter way of doing this: dog dog dog –––––––––––––––––––––––––– cat cat cat –––––––––––––––––––––––––– hamster hamster hamster Currently, I have to run 3 independent loops to ...
2
votes
1answer
36 views

Previous/Next button to next item in Matrix

I've made a projects structure with inside a couple of projects. On the homepage people can fill in a matrix with either a project or a textblock. I'm capable of looping through the detail pages in ...
1
vote
1answer
38 views

Get the variables of a loop from an include file

So my 1. file is "_overview-topicTeaser.twig" which is within a matrix: {% include 'modules/module-squareteaser/_module-squareteaser' with { squareTeasers: block.topicTeaserItems.all(), ...
1
vote
2answers
52 views

If featured or latest entry

I'm trying to include different markup if a blog post is featured. This is done via a Lightswitch. If there's is no featured entry then the latest entry uses this different markup instead. The rest of ...
1
vote
1answer
65 views

Macro for entry loop causing 'null' variable template error

I am new to the concept of Twig templates and I can’t get it right from the documentation … What I am trying to achieve is to have a reusable Blogroll snippet that outputs entries in different ...
1
vote
1answer
25 views

Allowing the user to update a CraftCMS pagination limit with listing filter options

I am building a pagination layout limiting the content to 10 because, well, it makes sense to break down large amounts of content to smaller chunks. But as there is so much, a user might want to ...
1
vote
1answer
298 views

Use Twig's batch filter with conditional

I am trying to make a grid of blocks using Twig. I have different types of blocks so I am using a conditional to test the block type and render different components per block type. The problem I am ...
1
vote
1answer
381 views

Simplify Twig/JS loop code

Can any help simplify this js/twig code? The code links to some tabs that show floorplans of the property being sold. The specified aria-controls refers to a supertable field called floorLevel that ...
1
vote
1answer
250 views

Next block inside of a loop

I’m struggling with getting the next block inside of a loop of a Matrix-Field. I’ve tried this: {% set nextBlock = entry.articleContent.offset(1).limit(1) %} {% if nextBlock.type == "textBox" %} {{ ...
3
votes
1answer
362 views

Getting the last X number of pages in pagination

I am working on a pagination for some articles. I am using a for loop to get the 3 pages after and before the current page .getPrevUrls(3) and .getNextUrls(3) So far it looks like this, where 35 is ...
1
vote
1answer
71 views

How do I loop through two sections as one set

I'm trying to loop through two separate channels, but combined together. And then just check which channel the entry belongs to in the loop to display it correctly. This is how I had it done in EE, ...
1
vote
1answer
40 views

Starting & Ending Loops with Eager Loaded Elements

Basically, I have two sections of a page. In one section of the page, I want to output the first 8 entries in a loop. In the next section of a page, I want to output from the 9th entry to the end of ...
3
votes
1answer
106 views

Start a Loop at the nth Entry in a Structure and Loop to the End?

I'm trying to start a loop at the 8th entry in a structure and then loop through the remaining entries in that structure and stop once I reach the end. How would I accomplish this in Craft?
1
vote
1answer
41 views

divisible by strange issue

I have an unusual issue with a for loop divisible by. The code works fine initially as it loops through the entries and closes a the list element on the 4th loop. However when it gets to the end of ...
1
vote
1answer
183 views

Counting included child blocks in the Neo plugin

In the Neo plugin, I've made a block that has the option to add 3 child blocks underneath it. This is the code from the parent block: {% extends 'neo/default' %} {% block blockContent %} <...
1
vote
1answer
35 views

A tabbed UI for child entries

wonder if a guru could help, I am nearly there, just stuck on the right call. Building a standard css/jquery responsive tab solution. I am pulling back child entries to populate a parent page with ...
1
vote
2answers
221 views

Loop by column from a table

How can I loop from col2 to col4 ? Or loop by column heading handle? Remplace {{ row.col2 }} <ul class="features small-font-size"> {% for row in block.tableHandle %} <li data-...
1
vote
1answer
175 views

Attempting to create a complicated grid layout with batch

I'm trying to create the following layout using batch, but I can't quite get it right... This is how far I've gotten: {% for entry in items|batch(3) %} <div class="row rowDivider"> {% ...
1
vote
1answer
45 views

Search then loop through files that were uploaded via FTP

Is it possible to search a server folder containing image and video files that were previously uploaded via ftp and then loop through those files in the entry template? Each entry has a unique Log ID ...
1
vote
1answer
229 views

loop.last of a certain block type

What are I doing wrong here? I'm setting block types 'stripCustom' and 'stripShowroom' to 'stripBlock' {% set stripBlock = entry.contentImage.type(['stripCustom', 'stripShowroom']) %} Then in a ...
2
votes
1answer
290 views

How to get first child URL within Craft/Twig Nav tags

I have a navigation structure as follows: {% set page = entry ?? category ?? null %} <ul class="nav menu--main"> {% nav entry in entries %} <li class="menu__item{% if page and ...
1
vote
1answer
99 views

How Do I Restart an Entries Loop Once It Hits the Last Entry

So I've got a Matrix block that is pulling in some entries and I'm looping through the entries in that block in a template. I'm then pulling a text field from each entry and putting it onto a page. ...
1
vote
2answers
677 views

Check if current entry is in loop and add class

I'm super new to both Craft and Twig so, apologies in advance!! I'm looking to determine if the current entry I'm on is in a loop being called on that page. I have loop that goes through the entries ...
0
votes
1answer
119 views

Display all entries matching field of a section

I have two sections: Games Publishers Games has a field called 'GamesPublisher' that is Entries type (set to Publishers) I have a publisher called 'Microsoft' with an ID of 49. I want to display ...
1
vote
1answer
46 views

Display all entry titles on one line during FOR loop

I have a FOR loop that should be displaying all the entry titles on one line. But instead, it is outputting them on separate lines. I want to see: Developer: Jane Doe, Jim Doe Instead, I am ...
0
votes
2answers
254 views

Loop through related section's entries

I have two sections: games publishers For example, a games entry title would be "Mario Brothers" and a publishers entry title would be "Nintendo" On the entry page for Nintendo, I want to display ...
0
votes
1answer
448 views

Loop through all possible options of a Dropdown-field

I'm currently trying to create a for-loop that loops through all options of a dropdown field created in Craft. I have a field called "Season", with the possible options to choose from being "2015/16" ...
1
vote
1answer
243 views

Get all images from a section

I want to get all images from the section projekte which are bound to the asset field bild I then want to fiddle around with .limit() and maybe random filters. So I grabbed all images like described ...
1
vote
1answer
90 views

Page redirects permanently to itself [closed]

I am posting this in case anyone will encounter this problem. I also reported a potential bug about that. (see here: https://github.com/craftcms/cms/issues) When you start to suddenly get redirection ...
0
votes
1answer
304 views

Uploaded .gif only loops once instead of infinitely [closed]

Having a problem where uploading an infinitely looping gif only loops once. I've tested it with and without image transforms and get the same issue. I know there there was an issue previously stated ...
2
votes
1answer
181 views

How do I group matrix blocks into batches of 4?

I am building a site which uses one content type as its primary holder for content. This is to make content editing easier on the content editor. All URL's are primarily accessing this one content ...
2
votes
2answers
53 views

Can I exclude a commerce address by ID when retrieving a list of addresses?

I would like to retrieve a list of all commerce customer addresses except for one. When working with entries, this can be done with the {id: 'not ' ~ some.id } parameter. This doesn't seem to work ...
2
votes
1answer
223 views

Display text field from Matrix of an Entry Field in Matrix

Question is similar to some others I've looked through but their solutions don't work as there are some differences. Currently this doesn't output any of the fields I try to access within the ...
3
votes
1answer
231 views

The twig syntax for this for loop

I am trying to develop a loop in a craft template that adjust the numbers of rows and awards per row based on the total number of awards. The numbers are all coming back correct but I am struggling ...
2
votes
1answer
593 views

Matrix: get the index number of a certain block

I have a matrix set up with some blocks in it, and one of those blocks is to add "steps" to a page in a matrix. Now I'm trying to get the number of the step so that they only have to enter the content ...
1
vote
1answer
82 views

Loop through assets field on detail/product page

I am trying to loop through an assets field called gallery on entries in a commerce products channel. This field can have multiple images in it. I can get this to work on a channel listing page ...
3
votes
1answer
887 views

How do I get just the first entry with a 'for' loop?

I have this this code - {% for entry in craft.entries.section('news').first() %} <div class="container" id="featured-news"> <div class=col-md-6> <h2 class="news-...
3
votes
2answers
1k views

Loop divisible by issue

Code: {% for block in entry.testimonials %} <div class="col-24 {% if loop.last %}gutter-bottom{% else %}gutter-bottom--none{% endif %}"> <div class="section inner"> <div ...
5
votes
1answer
153 views

What is the difference between 'nav' and 'for' for looping?

I am new to craftcms and did a look through on the documentation just recently. I am at the part where it explain about the Categories Field and found out that we can loop through the ...
0
votes
1answer
2k views

Issue with twig loop.first loop.last contained in nested for statement

I'm trying to pull out selected categories in a front-end user profile. The cats have 2 levels and need to be pulled out into a nested list with only the selected options. I've tried different ways of ...
3
votes
1answer
148 views

Combing an If Statement with Pagination

I'm trying to pull all the entries in a category that have a multi-selection selected and then paginate it. If I just do the below, it works perfectly fine. {% set entriesRed = craft.entries....
1
vote
3answers
136 views

Parse html on first and last occurrence of a matrix block type in a series of that same block type

I'd like to wrap a series of block.type (images and description) in a div. So at the first iteration of this block type it needs to parse the start of the div. In the last iteration of this block type ...
1
vote
1answer
260 views

Loop through fields in field layout when `entry` is not set

Is there a way in a template to loop through the fields in a field layout without having to tie them to an entry? I'm currently grabbing that list with entry.getFieldLayout(3).getFields(), but that ...
3
votes
1answer
440 views

How to list all existing values for a field across site

I have a huge set of entries which have a lot of fields. Say, the entry type is a 'book' and fields are 'keywords', 'year', 'authors', etc. Now I'm building a filter form which would allow user to ...