Questions tagged [variable]

Variable a symbolic name associated with a value that may be changed

Filter by
Sorted by
Tagged with
4
votes
1answer
530 views

Does Twigs 'addGlobal' exist in Craft?

I know Craft gives us access to Twigs getTwig template service; so when I attempt to use the addGlobal function like so: craft()->templates->getTwig()->addGlobal('var', $var); ... nothing ...
6
votes
2answers
4k views

Calling variables, dynamically

I've got a parent template which contains the following code: {% include '_layout' with {'countryCode': 'au'} %} I have a global set with the handle au_Variables, and within that a field with the ...
4
votes
3answers
5k views

How can I make a template output its own filename?

Is it possible to output the template name being used? Using a global variable or something similar? I am wanting to check which template is being used in a conditional.
4
votes
1answer
218 views

Reusing logic to set string variables

I would like to set some variables for every entry within a section ('courses'), and then use those variables in loops that are filtering by entry types and categories. Some simplified markup: <...
2
votes
3answers
31k views

Can I set a JS variable to a Twig output tag?

This came out of a previous question I need to set a variable of a tag group that I can reference in jquery for use with a plugin. I'm declaring this variable in a tag so my included js files can ...
1
vote
3answers
1k 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 ...
6
votes
2answers
13k views

How can I incorporate a variable into a string?

How can I incorporate a variable into a string, so that the result is a longer string that includes the contents of a given variable? For example, I have a variable called apple and its value is "...
4
votes
3answers
4k views

How can I globally set variables?

Originally at Include a template that sets variables (global template variables). I have a number of templates and layouts but every layout includes a global header in which the meta data is ...
3
votes
1answer
9k 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 %} ...
2
votes
1answer
2k views

Can you pass a variable with includeJsFile?

Can you do something similar to using "with" in twig's include tag (http://twig.sensiolabs.org/doc/tags/include.html), but instead with includeJsFile? I am using a plugin to filter my entries by ...
8
votes
2answers
18k views

Use a Twig macro to set a variable

Is there any way to use a macro in twig to define a variable outside that macro? For example, say you want to use a macro to set a variable that stores an entry's parent (I know you can do this much ...
5
votes
1answer
2k views

Getting environmental variable via plugin

A similar question was answered before, but I was wonder how I might be able to return the same query from within a plugin (php)? Convert this: {{ craft.config.environmentVariables.baseUrl }} To ...
4
votes
1answer
600 views

Best practice on how to hand over variables with links?

You sometime want to pass specific info from one page to another. How do you do that with twig and are there explicit Craft methods to do this? Can you do this without exposing the variable in the ...
3
votes
2answers
3k views

Dynamically load craft entries based on twig variable

I am looking for something quite simple, but I still can't find a way to do it in twig syntax. So basically here is my code: {% set upperlimit = 3 %} {% for entry in entry.getChildren() %} ...
1
vote
1answer
445 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 ...