Questions tagged [set]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1
vote
1answer
108 views

Setting Variable to Specific Category for Loop

How do you set a variable to a specific category so you can do an if or for loop? I have entries(staffList) associated to categories (Management,Staff,Other,PartTime)and I am trying to set a variable ...
2
votes
1answer
36 views

Is it bad practice to re-use array variable name?

I have this line {% set entries = craft.entries.section('x') etc etc %} Which I use to pull data for a header in my _layout.html template. Then later, knowing I am done with the array, inside a ...
0
votes
1answer
64 views

Image from Another Entry

Is it possible to pull an image from another entry? It seems like it would be simple. I've read a lot of posts and documentation, and feel like I'm close... {% set entries = craft.entries.slug('...
2
votes
2answers
999 views

How can I filter selected/related entries by their categories?

I have a section called "Events" and an Entries field, we'll call myEntriesField to select related entries from another channel called "Exhibitors" On the Events page, I need to display the related ...
1
vote
1answer
333 views

Reuse chosen dropdown field value on frontend

I would like to choose entry values from a frontend dropdown and reuse the chosen value directly. {% set entries = craft.entries.section('mountainbikes') %} <select name="year"> {% for entry ...
0
votes
1answer
136 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 ...
3
votes
2answers
798 views

How do I set a specific entry in a template with “set”

This won't work in a template: {% set entry = craft.entries.id(43) %}<h1>Titel: {{ entry.title }}</h1> But this does: {% for entry in craft.entries.id(43) %}<h1>Titel: {{ entry....
1
vote
1answer
2k views

How to include a section name in the page title?

I can get Craft to generate page titles for entries and individual pages using: {% set title = entry.title %} and {% set title = "News and Insights" %} But I need to be able to generate a full ...
1
vote
1answer
357 views

Get entries from client checked options

I have a checkbox field to enable my client to choose what entry categories to have as an article feed on a page. How can I output the checked option categories when setting the entries in the for ...
1
vote
1answer
58 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
213 views

How to write query with startdate <= now && enddate >= now?

I'm trying to make a query which has 2 conditions who has to be true both. In PHP I should use && to get this. startdate <= now && enddate >= now. How do I write this in Craft twig? ...
3
votes
1answer
6k views

Variable variables in Twig

I'd like to create a variable from another variable. What I got right now is something like this: {% set language = fr %} {% if language == "en" %} {% set fooAddress = en_foobar.globalAddress %} ...
1
vote
3answers
896 views

Replace placeholder string in text field with HTML generated by Asset query

I have a Matrix block with a text field and an Assets field. The text field has a Markdown filter applied to it. I'd like the content owner to be able to enter a placeholder reference to one of the ...
1
vote
1answer
2k views

Combine variables with text to make variable

How can I create a variable that is a combination of two variables with text? For example, I know the following is wrong but is something like this possible: {% set foo = 'foo' %} {% set bar = 'bar' ...
2
votes
2answers
679 views

Order entries based on last string of title

I would like to get the last string of a entry title and order entries based on that. Basically the people title are their full names and I am trying to find their last name and filter based on that, ...
4
votes
1answer
232 views

Limit search results for users by tag (and limit to 5 tags)

I've read as many forum posts and documentation but am a little stumped over a specific use-case. Currently the search page grabs the url segment, loops through a verified user group, and uses the ....
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 ...
1
vote
1answer
101 views

How to extend a variable name to fetch another?

I’m trying to append a 'x2' to the end of a variable name to call another variable. For example: imgSize might be set to predefined variables like imgColumn4, imgColumn6 or imgColumn8. In that case ...
0
votes
2answers
886 views

Entry field not outputting after {% set… %} code in template

I have an {entry.footer} field outputting just fine everywhere before {% set entry... %} Added {% endset %} tags after closing anchor tag and caused an error. Any idea what the issue is? {% extends "...
8
votes
2answers
24k views

Is there a way to define a global var within a twig block?

Something that would work like this: {% block A %} {% set testVar = "foo" %} {% endblock %} ... {% block B %} {{ testVar }} {% endblock %} The scope of testVar seems limited to {% block A %} I'...