Questions tagged [loop]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
0 answers
39 views

'Endless Loop' Kiosk Crashing Randomly - Craft 2

I am needing an 'endless loop' through my entries for a kiosk application, and was wondering if this approach would work for that? I had been using just Twig on a template, cycling through my selected ...
user avatar
  • 368
1 vote
2 answers
95 views

`loop.last` throws 'variable is not defined when looping with a condition' error

I have a Neo field that contains blocks for hero, body, button etc. For every block except hero, I want them to be wrapped in a containing element. So I have this: {% for module in entry.pageBuilder....
user avatar
  • 509
1 vote
1 answer
72 views

Loop when removing existing ID's

I'm using this code to remove duplicate entries from my loop: {% set existingIds = [] %} {% for entry in entries %} {% if entry.id not in existingIds %} <div class="column is-4">...
user avatar
2 votes
1 answer
46 views

Getting entries excluding the first

I'm trying to set up having the first entry pull in and then later down the page pull in the remaining posts (as I need to break the loop with other content). I'm a little unsure how to set up pulling ...
user avatar
  • 879
1 vote
1 answer
35 views

Output loop position number

Good Evening, This is probably something really simple, but I need to output the position of the entries in a query within the loop {% set relatedEntries = craft.entries().section('memories').limit(10)...
user avatar
1 vote
2 answers
75 views

Getting blocks from matrix and injecting them throughout a page, NOT a single loop statement

I have a matrix field that allows the user to add little 'designed' features throughout the page. These are placed in certain positions on the page and so I want to loop through these but because they ...
user avatar
  • 1,824
1 vote
2 answers
101 views

How to loop through multiple entries fields

I'm creating a dynamic side navigation where pages can choose which sidebar it wants to use. This is selected by an entries field called 'sidebar' - called in line 2. To create this I've made a ...
user avatar
1 vote
1 answer
137 views

how to output all images in an entry's loop

Unfortunately I'm still very new to Craft, but I have a question to which I haven't found an answer here or in the Docs or the ones I found don't seem to work in my case. I want to output all the ...
user avatar
3 votes
1 answer
346 views

How to duplicate entries and loop them without getting a Twig or deprecation error?

I'm trying to duplicate entries inside a macro, which will displays duplicated items inside a carousel. It's not possible to merge Element Queries. Even if it's possible to merge IDs, merging an ...
user avatar
0 votes
0 answers
29 views

Images won‘t display in an entry loop

Unfortunately I'm still very new to Craft, but I have a question to which I haven't found an answer here or in the Docs or the ones I found don't seem to work: Why doesn't this entry-loop output a ...
user avatar
1 vote
1 answer
55 views

Reuse items from array with forloop

I have a loop of a list of regions on a project, this could be an infinite list of areas as my client's customer-base grows. The project branding has four key colours, I have these in an array: {% ...
user avatar
  • 1,032
1 vote
1 answer
73 views

A for loop within a for loop that is split

Possibly a bad question title...sorry but wasn't sure how to describe it. Basically I have a for loop that every 4 items I want to pull in a different item from another loop. This is a series of Q&...
user avatar
  • 1,824
1 vote
1 answer
494 views

EVENT_BEFORE_SAVE_ELEMENT Saving element loop in task/queue

I'm calling EVENT_BEFORE_SAVE_ELEMENT to trigger a task that then updates the entry, but it's causing a loop? The event is triggered when a specific entry type is saved: Event::on( Elements::class,...
user avatar
1 vote
1 answer
43 views

Ordering Looped Results by Field's Numerical Value

I’m looping through some text fields on the form results page and need to order the numerical output from low to high. How would I do this using twig? {% for field in submission %} {% submission[...
user avatar
  • 1,107
2 votes
1 answer
234 views

Loop through Matrix Block fields within a Switch Case and retain HTML structure

I'm struggling to get my head around the syntax to output information in a correct HTML structure. At the moment I have this: {% for block in entry.menuBuilder %} {% switch block.type %} {% case '...
user avatar
  • 1,173
2 votes
2 answers
199 views

Creating entries loop with nth loops across unordered lists

I'm looking for some help with the most efficient and performant way to generate this loop. | COL 1 | COL 2 | COL 3 | | 1 | 2 | 3 | | 4 | 5 | 6 | | 7 | 8 | 9 | | ...
user avatar
1 vote
1 answer
32 views

Craft 3 - Matrix Block for currentUser

I have a Matrix field named -> certificado with block -> certificados and fields -> nomeDoCurso, curso, certificado My Matrix block has no entries but is associated with a user. How can I fetch ...
user avatar
1 vote
1 answer
360 views

Matrix Field - variable entry does not exist

I'm trying to loop a Matrix field that has one block containing 3 items. {% for block in entry.galeria.type('itemsGaleria') %} {% if block.titulo|length %} {{ block.titulo.first }} {% ...
user avatar
1 vote
1 answer
228 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 ...
user avatar
  • 213
1 vote
2 answers
109 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 ...
user avatar
  • 1,032
2 votes
2 answers
308 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 ...
user avatar
  • 333
1 vote
1 answer
101 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 ...
user avatar
1 vote
1 answer
57 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 ...
user avatar
1 vote
1 answer
29 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 ...
user avatar
  • 284
2 votes
1 answer
111 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 ...
user avatar
  • 43
1 vote
1 answer
138 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(), ...
user avatar
1 vote
2 answers
136 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 ...
user avatar
  • 879
1 vote
1 answer
156 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 ...
user avatar
  • 117
1 vote
1 answer
36 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 ...
user avatar
  • 1,032
1 vote
1 answer
751 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 ...
user avatar
1 vote
1 answer
649 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 ...
user avatar
  • 543
1 vote
1 answer
645 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" %} {{ ...
user avatar
  • 215
3 votes
1 answer
964 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 ...
user avatar
1 vote
1 answer
277 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, ...
user avatar
1 vote
1 answer
73 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 ...
user avatar
  • 659
2 votes
1 answer
222 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?
user avatar
  • 659
1 vote
1 answer
67 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 ...
user avatar
  • 2,023
1 vote
1 answer
505 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 %} <...
user avatar
1 vote
1 answer
40 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 ...
user avatar
  • 333
1 vote
2 answers
670 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-...
user avatar
  • 11
1 vote
1 answer
252 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"> {% ...
user avatar
  • 31
1 vote
1 answer
67 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 ...
user avatar
  • 846
1 vote
1 answer
469 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 ...
user avatar
  • 879
2 votes
1 answer
726 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 ...
user avatar
  • 1,032
1 vote
1 answer
320 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. ...
user avatar
  • 659
1 vote
2 answers
1k 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 ...
user avatar
0 votes
1 answer
155 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 ...
user avatar
  • 303
1 vote
1 answer
49 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 ...
user avatar
  • 303
0 votes
2 answers
384 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 ...
user avatar
  • 303
1 vote
1 answer
565 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" ...
user avatar