Questions tagged [loop]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1
vote
1answer
44 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: {% ...
1
vote
1answer
15 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&...
1
vote
1answer
23 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,...
1
vote
1answer
33 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[...
2
votes
1answer
162 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 '...
1
vote
2answers
43 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 | | ...
1
vote
1answer
27 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 ...
1
vote
1answer
136 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 }} {% ...
1
vote
1answer
65 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
52 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
116 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
67 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
vote
1answer
48 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
43 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
68 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
68 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
87 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
28 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
487 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
477 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
373 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
513 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
114 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
51 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 ...
2
votes
1answer
168 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
54 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
257 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
349 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
209 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
56 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
313 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
431 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
141 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
927 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
137 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
47 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
319 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 ...
1
vote
1answer
484 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
319 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
115 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
314 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
212 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
57 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
304 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
283 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
771 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
94 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 ...
2
votes
1answer
1k 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-...