Questions tagged [loop]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1
vote
1answer
29 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">...
1
vote
2answers
71 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 ...
2
votes
1answer
43 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 ...
1
vote
1answer
14 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)...
3
votes
2answers
4k 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 ...
1
vote
2answers
61 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 ...
1
vote
1answer
73 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 ...
3
votes
1answer
216 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 ...
0
votes
0answers
28 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 ...
1
vote
1answer
52 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
48 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
382 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
38 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
211 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 '...
2
votes
2answers
155 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 | | ...
3
votes
1answer
887 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
31 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
313 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 }} {% ...
7
votes
3answers
17k views

Remove trailing comma from an output loop?

I want to create a comma separated list of categories to which an entry belongs, but without the trailing slash on the last element... can't work out how to remove it! {% for category in entry....
1
vote
1answer
128 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
94 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
271 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
95 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
52 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
116 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
1answer
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 ...
2
votes
1answer
99 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
2answers
122 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
127 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
168 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 ...
1
vote
1answer
34 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
686 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 ...
2
votes
2answers
64 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 ...
1
vote
1answer
432 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
614 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
596 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" %} {{ ...
1
vote
1answer
243 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
65 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
205 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
65 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
38 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
607 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
249 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
66 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
435 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
649 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
293 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
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 ...
0
votes
1answer
150 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
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 ...