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
1
vote
1answer
16 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
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[...
0
votes
0answers
24 views

How to create an array of items and fetch them with .all()?

Is there a way to create an array of items, fetch them with .all() and loop through them? For example: {% set array = array|merge([block]) %} {% for block in gallery.all() %} {% endfor %}
1
vote
1answer
80 views

Looping Related Entries with a Super Table

I need to loop related entries. I am using a SuperTable field with the handle "related" with an entry field with the handle "contentEntry" and two text fields for alternative text and descriptions. ...
0
votes
1answer
53 views

For loop through custom field in JavaScript

I'm using a script to animate four sets of numbers on a page. I would like the numbers to be editable from within the admin (a SuperTable field). Currently I have this: <ul class="counters"> ...
1
vote
0answers
143 views

Error while sending QUERY packet. PID=881 when using cache key

If I do: {% set cacheKey = block.id %} {% cache using key cacheKey if craft.app.config.general.cache %} {% for item in items %} <div class="swiper-slide ais-hits--item" data-id="{{ ...
1
vote
3answers
32 views

Keeping order of blocks like in backend

Fairly new user here. I am kinda confused how to template. I want to rearrange the order of blocks in my backend and show them in the right order in the front. Here is how i am currently writing a ...
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
59 views

Add conditional in a for loop

I need to add a separator if there are a multiple of types. How can this be done in a for loop? {% for type in entry.buildType %}{{ type }}{% endfor %} The outcome is similar to a breadcrumb nav, ...
1
vote
1answer
52 views

.limit(1) on asset field loop is effecting another loop on same page

I have an Asset field where the first image is used as a big 'feature' and then the rest are used as support further down the page. When I add .limit(1) to the for loop for the 'feature' image it ...
0
votes
0answers
52 views

How do I create an index page that loop through the table fields of its entries?

Every entry in a section has a table. The table depicts sales over 7 years. I want to create an index page that lists the title of each entry and the sales for each entry in the section. I know ...
1
vote
1answer
217 views

Match Matrix Fields Before Looping Through Results

I hope someone has an example or something similar they have done in Craft before. Her is what I have. Structure: Section -> Flight Company Matrix Name -> Plane Details Matrix Block: Plane Model ...
0
votes
1answer
40 views

My `for` loop has fallen…and it can't get up

I want my <ul> to show a single tag representing all "active" entries ( "active" using a custom lightswitch field in the entry: fellowStatus. Each tag is a year (e.g. 2014, 2010, etc) E.g. if ...
1
vote
1answer
31 views

Omitting repeated content in a for loop

I'm trying to use this slightly differently: How do I omit similar content in a for loop based on the first letter in title? I have a for loop with several entries. One field is a drop-down with a ...
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
490 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
146 views

Dynamic Navigation with Condition to check slug

I'm trying to achieve one pretty simple thing, but putting it into my dynamic nav is making it a little difficult. I want to have a little number of the total amount of entries in my channel "listings"...
1
vote
1answer
134 views

Changing first matrix block

I'm trying to target the first matrix block and changing the structure of the HTML, but nesting an IF statement within the loop but it's actually not doing anything, instead it's just displaying both ...
1
vote
1answer
21 views

error when trying to loop through grouped entries according to dropdown field

I was trying to follow this example from stack overflow to loop through a list of entries and output them by a custom dropdown field {% set allEntries = craft.entries.section('resource').find() %} {% ...
1
vote
1answer
30 views

Archive Not Returning Correct Date Variable

I'm using the technique for creating an archive that's in the Craft docs: https://craftcms.com/support/entry-archive I'm archiving by day, so my code looks like this: {% set agendaEntries = craft....
1
vote
1answer
379 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" %} {{ ...
0
votes
2answers
23 views

How to disable loops from automatically wrapping non-marked up content?

So I've got a completely clean install of Craft 3: RC 2. I've installed Redactor, and nothing else. In the templates/index.twig file; this is all I have: {% set test = ['one', 'two', 'three'] %} {...
1
vote
1answer
2k views

loop.index is not returning correct number inside nested loop with inline if conditional

I'm getting incorrect loop.index results with the following code. It returns "1" for each entry returned. Is there a different way this needs to be written? {% for order in orders %} {% for ...
1
vote
2answers
46 views

How to pull a single podcast source, using the Matrix field and loop?

{% if block.type == "podcastBlock" %} {% for category in block.podcastChannel %} {{category.title}} <audio class="mp3" controls> {% for entry in block....
1
vote
1answer
75 views

Looping through Entries based on MultiSelect Field Selection

I’ve got a people entry type that has a peopleCategory multiselect field. I’m wanting to loop through all the people and grab the ones that have a a specific item selected in the multiselect field (in ...
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 ...
1
vote
1answer
97 views

Filtering out section entries

I'm quite new to Craft CMS and have takeen over an application (using Twig templates). I'm trying to run a filter but not having much joy so maybe I might get some help! So, there is a people ...
2
votes
1answer
201 views

Load entries based on category field value while multiple categories are selected

I have an activity calendar (more like a weekly schedule) which filters per day and per category. Because there are so many activities I can't just load them all in at once so I use some sort of Ajax ...
3
votes
2answers
749 views

How do you use a for loop to output to JS?

I have a map generated in JS. I need to set the country-id and url for each country. Both 'country-idandurlare fields in my Craft categories groupcountries`. { "country-id": "FR", "url": "...
1
vote
1answer
226 views

Sort entry titles alphabetically excluding 'The'?

I need to list the names of all of my entries in alphabetical order excluding 'the' (which could only be at the beginning). I've looked around online, but I was only able to find a code segment (which ...
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
646 views

For loop, if statement, then limit

I've created two global variables which my content creator is going to use to turn off a bunch of articles and turn on a bunch more which a slight change in the Global. I have a page where there is a ...
2
votes
1answer
112 views

For loop with custom order

So I'm trying to loop through some entries and order them by in a specific way. For an example let's say I have the following entires: Example01 Example02 Example03 Example04 I now want to loop ...
2
votes
1answer
289 views

Get an image from a random entry

I have a section with an text field and an image field. the asset field may sometimes be left blank. in this case, in my template, i want to grab the image from another random entry. This is the code ...
0
votes
0answers
93 views

Imager plugin not working inside the loop

so I am using trying to use the Imager plugin to compress my images. It works fine this way: {% set imagePath = "/path/to/img.jpg" %} {% set compressed = craft.imager.transformImage(imagePath,...
2
votes
1answer
223 views

Get future multi-day event entries with custom date field

I have an event section with custom fields for eventDate and eventEndDate. I'm listing upcoming events in my template using: {% for event in craft.entries.section('events').eventDate('>='~now)....
0
votes
2answers
254 views

How do I omit similar content in a for loop based on the first letter in title?

I've got a for loop that is returning the first letter of the entry title. I have a number of entries so I almost get a complete alphabet except that there are too many of many letters. I only want ...
2
votes
1answer
433 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 ...
2
votes
1answer
1k views

Limit the for loop returns with an if statement

I've got a for loop working perfect with a limit of 5. Then I throw in the if statement to filter those entries that correspond with a global variable I have set. The problem is the if statement is ...
2
votes
1answer
33 views

I want to display entries that have a field that is the same as a field in a global variable

There is a publishMonth (multiselect) and publishYear (radio buttons) field in each article. They do not correspond to an actual date. Each article is is associated with one year, or one or more ...
1
vote
1answer
145 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. ...
2
votes
3answers
632 views

Making an entry grid with Batch 2,3 (2 in row then 3 in row)

I'm trying to make a News item grid. I'm looking for a solution to output 2 type of "rows". One that shows 2 entries and the other shows 3 entries. I tried playing around with batches already but can'...
1
vote
2answers
931 views

How can I concatenate 2 variables to access array values?

I am using this SO post to try to concatenate two variables in twig. I am very close, but can't seem to get over the hump of rendering the correct syntax. This is what I am currently using: {% for ...
1
vote
1answer
305 views

Image(r) transform and for loop

I'm stuck with the .first() element and why the for-loop code won't work. <div id="header-slider"> <ul> {% set image = entry.bannerSlider.first() %} {% set ...
1
vote
1answer
66 views

loop trough whole array inside a field

I want to write an entire loop into a field like this: Obviously this is not working. What would be the correct syntax when twig is written inside a field? Also is there a name for the twig tags ...
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
1answer
181 views

For loop does not display all entries in section

I have a for loop for all entries. There is no limit set, yet the loop is not displaying all the entries. The missing entries are the oldest. These missing entries do appear on category specific ...
1
vote
1answer
953 views

Looping through rows in a Super Table

Very new to Craft & Twig. So I get the following error: Impossible to invoke a method ("url") on a integer variable ("0") with the below code: {% if module.type == "rotator" %} <div class="...
1
vote
1answer
485 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
645 views

Comparing current date to multiple entry matrix date fields

I need to display an entry only if the date fields within its Matrix are current. So, only display if the startDate is greater than or equal to today and the endDate is less than or equal to today. ...