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
2answers
1k 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
341 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
48 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
188 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
1k 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 == "...
1
vote
1answer
502 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
744 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. ...
2
votes
2answers
7k views

Total sum within loop

I have simple loop: {% for total in thing %} {{ total.seatsKids }} {{ total.seatsParents }} {% endfor %} This results in a string of numbers eg. 1 3 4. I want the sum of all numbers. So how do I ...
1
vote
1answer
170 views

Can't access data in Matrix field

Stuck on a problem at the moment… trying to output a Rich Text field (copy) from an entry. The copy is contained in a matrix field (so: Entry -> Matrix Field -> Copy Field) but I can’t access it no ...
1
vote
1answer
66 views

Error in case of nested for loops

I have a comment section with comments and subcomments. A comment relates directly to the blog post while a subcomment relates to a comment. Now, I have the following problem on the entry page: ...
8
votes
1answer
4k views

Display entries if Field Date is past Now

I'm trying to make a upcoming and past event page. I can make an if statement for displaying the past or upcoming events but the problem is if I limit the amount of entries to be displayed I realised ...
1
vote
1answer
60 views

How do I make my variable available inside an assets loop?

I have an entries field called 'customerLogoBarUrl'. It contains one entry. So I can do this: {% for item in entry.customerLogoBarUrl.limit(1) %} {% set theUrl = item.url %} {% endfor %} But then ...
2
votes
1answer
433 views

Is there a better way than stacked if else

i am using a slider in my template, and depending on if the user filled out values in the craft matrix (slides can have up to 4 rows) i want to have twig compile only the necessary code. I am not sure ...
3
votes
1answer
2k views

Check and remove repeat entries from loop

Is it possible to loop through the list of entries and filter out any that have the same ID as any of the other entries (duplicates)? I have a specific case where this is an issue. I want to keep the ...
1
vote
1answer
640 views

for loop: get the title of the first element of an entries field

I want to get the title of the first element from a entries field in a for loop. I think its easier to understand with a code example: {% set programs = craft.entries.section('program_point').block....
1
vote
1answer
291 views

Streamlining a loop with a bunch of conditions

I'm sure there must be a tidier and more efficient way of doing this so thought I'd throw it out there for some opinions. Building a site that has the usual lists (in grid format) for Blog, Gallery, ...
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 ...
2
votes
1answer
130 views

Looping out a lot of entries.

Ok, so I'm looping through a lot of entries. It's a large request, and I had to up php memory limit to 512M. But I'm sure there is a less memory consuming way to do this. Also, I want to cache the ...
2
votes
1answer
191 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
1answer
377 views

How can I loop through a Channel entries asset folder?

Basically, for every entry that I add to my 'Portfolio' channel, it creates a sub-folder inside assets/portfolio. For example I have: assets/portfolio/entry-one assets/portfolio/entry-two On my ...
2
votes
2answers
352 views

Reverse count with paginated entries?

I have this loop {% paginate craft.entries.section('sermons').limit('10') as pageInfo, entries %} {% for sermon in entries %} ... {{ loop.revindex }} ... {% ...
1
vote
1answer
471 views

Correct way to merge craft.user field arrays and use outside the loop?

I'm using preparse field plugin to limit the amount of tags a user can add to his account. I've modified the code slightly so the tags are processed as a comma, separated, list. The plan is to ...
1
vote
1answer
124 views

How to add users to the search results?

I'm trying to display three different sets of data in search results. The first two, News and Services I can easily concatenate by the following: {% set searchSections = craft.entries.section(['...
1
vote
1answer
766 views

Create a new row every 3 items in a matrix

I need to output a row every three items in a matrix. Here is what I have so far. The problem is that this outputs a row every three items but it duplicates each matrix item three times and puts them ...
1
vote
2answers
1k views

Only display entries based on a field conditional

Hey I am trying to get 4 entries, but only want 4 that have a body length > 100. How would I accomplish this? {% for entry in craft.entries.section('artists').order('RAND()').limit(4) %} // only ...
1
vote
3answers
518 views

Can't get checkboxfield values to show

I'm trying to build a filter and for that I want my client to be able to select a few options, which I use as classes for in my filter. I chose for a checkbox field and set it up in the backend. Now ...
2
votes
1answer
1k views

Sort / Order Entries on select or button click

I have a page on my website were I display alot of entries. Now I want those entries to be sorted by Date, Title etc. I know how to change that hard coded but I want to make it dynamic with a <...
4
votes
2answers
1k views

Is it possible to change a loop if mobile browser is detected?

I have a loop to go through my products which go in batches because they need to show detail info every third entry. When the Website is viewed from a mobile device, Tablet or Mobile I want it to loop ...
1
vote
1answer
735 views

Filtering entries by multiple categories with multiple filters

I'm trying to build a category filter on a page that lists houses that are for sale. The idea of the filter is to make it possible to select houses which, for example, are for sale or rent, have a ...
3
votes
2answers
168 views

Help developing point system for sports league (w/o plugins)

I'm in the middle of a very long project developing a league site for the National Collegiate Wrestling Association in my spare time (once finished, could be a great showcase for Craft). Currently, I'...
10
votes
1answer
5k views

Advanced query/filter based on date and values

I have a channel of events with a field ‘eventDate’ for the date/time of the event. Within that there are ‘types’ of events ‘eventType’. What would be the most efficient way of outputting the NEXT (...
1
vote
1answer
91 views

Home page loop once, other pages loop through all

I only want one block on the home page, other pages can loop through all of them. Is there a more efficient way to write this? {% if craft.request.getSegment(1) is empty %} {% for block in ...
1
vote
1answer
123 views

Looping through returns nothing after using dynamic routes to get the entry type and category

I'll explain a bit of the structure of the content and then proceed to the issue. So i have a website with a shop in it with the url mysite.com/shop/, it is an channel section, and its template is ...
7
votes
2answers
741 views

Add ordinal suffix to loop.index

I'd like to add an ordinal suffix to the loop.index variable within a for loop. For example: 1st 2nd 3rd
2
votes
1answer
130 views

SET versus FIND

As I understand, I have (at least) the following two possibilities to list entries of a channel: Possibility 1: {% for entry in craft.entries.section('example').find() %} Possibility 2: {% set ...
4
votes
2answers
11k views

twig for loop put every 2 elements in a new container

I have this loop: {% for div in myHandleHere %} <div> {{ block.text }} </div> {% endfor %} That actually outputs something like: <div> one </div> <div> two </...
3
votes
1answer
650 views

Nesting level too deep when looping through matrix blocks

I'm running into a nesting level error when looping through matrix blocks, and I can't quite figure out what the problem is. The problem arises when I use a variable to track the type of the previous ...
2
votes
1answer
251 views

Next / Prev and looping/cycling entries instead of reaching the end of the selected results

Is there a way to be able to use entry.getNext(params) to return back to the first entry when you're viewing the last entry in the parameters? With the result of looping/cycling through all entries ...
0
votes
1answer
53 views

retrieve assets from an entries

Im looking up the last 2 entries like this {% set entries = craft.entries.section('report').limit(2) %} My entry got an assets field called 'portfolio'. I would like to retrieve 8 images in random ...
1
vote
2answers
1k views

Matrix loop nesting issue using switch

Anyone know if it's possible to check what the current field is while in a loop of a matrix block? Running into an issue with a matrix block in my loop for how I want to output the content. {% case '...
2
votes
2answers
420 views

How Do I Select the second instance of a certain block type

We use a matrix field for the article content on our site. We have different blocks for different content (text, images, embed etc..) and we have optional fields that are outside of the matrix that ...
1
vote
1answer
176 views

Prevent queries based on condition

I have a set of parameters that need to be checked before outputting an entry in a particular section of a website. The code for that looks somewhat like this: {% for slide in craft.entries.section('...
1
vote
2answers
290 views

Loop based on date (with math)

I would like to loop through entries only if the current date/time is before 5am on the following day from when the entry's eventDate (custom field mind you)is. In other words I may have an event at ...
1
vote
2answers
1k views

Get last row in table field for loop

How can I determine if the row being returned from a table field in a for loop is the last row?
2
votes
1answer
171 views

calculating average ratings from a series of review fields

I've setup a section for reviews with several fields as numbers for a rating 0-5, I'm trying to figure out how to get the total of all reviews and sum of all reviews to provide a single average for an ...
1
vote
1answer
1k views

Creating JS slideshow with Twig “for” loop

I have an entry with a matrix field called quantification containing plain text and asset field. Im looping through the matrix field and for each asset quantification I have a new gallery. Each div ...
2
votes
1answer
2k views

Why are variables persisting inside of my for loop?

Is anyone able to tell me why variables which I've defined inside of a for loop are persisting and retaining their values on into consecutive iterations? In order to overcome this, I've had to set ...
2
votes
2answers
1k views

Set dynamic class in for Loop

I have this simple element model and I'm trying to add dynamic class within loop. So every time a model outputs, It outputs dynamic class. Can't go for another loop within loop, in case I could, ...
7
votes
2answers
59k views

How do I set a variable in Twig if a value exists more than once in a loop?

How do I loop through entries and set a variable if there are any duplicates in the data I'm checking? In my case, I need to check if there are more than one entry per year. The variable I'm setting ...