We’re rewarding the question askers & reputations are being recalculated! Read more.

Questions tagged [variable]

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

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

Redirect to template from controller and pass data

I am building a custom login process which follow these steps: Request user email (submits to custom controller) Check if user has an account If they have an account, show a form requesting their ...
1
vote
1answer
26 views

Field removed from entry layout is still displaying

So I'm setting my meta author tag this way: <meta name="author" content="{% if seoAuthor is defined %}{{seoAuthor}}{% else %}{{globalSeo.seoAuthor}}{% endif %}"> seoAuthor is a field that ...
0
votes
1answer
54 views

Passing variables into twig components

Based on this interesting article: DRY templating with Twig and Craft CMS. I found myself trying to update the approach with include instead of macro following reading I had about twig 2 and craftcms ...
1
vote
1answer
22 views

How do I show errors for a new front end entry form?

I'm using a front end form so logged-in users can create a new entry ("post") or edit an existing entry. Here's the controller for figuring out whether it's a new or existing entry: {# Get the entry ...
1
vote
1answer
47 views

Need help trying to pass a variable of a related entry

On my page, I have a form which is using Freeform (Solspace). I'm attempting to setup a custom redirect URL for the form. The form will apply to numerous entries in a channel and some will require ...
1
vote
1answer
68 views

Passing optional variable values into an include template

Craft noob here. I have an include file which I'm calling a "component" so I can reuse it across the site. The component is set up like this. <h2>{{ heading }}</h2> {{ bodyContent }} {% ...
1
vote
1answer
32 views

Craft 2 - Returning Value in Variable from Plugin to Template

I am working with a plugin and wish to return a value from it to the template that calls it. In my plugin, there is an XML feed call, and I would like to pass a value(variable) from the plugin to the ...
0
votes
0answers
90 views

Incorrectly setting module template variable

Getting error: Calling unknown method: craft\web\twig\variables\CraftVariable::markAsReadModule() Trying to use a template variable that I created in my Craft 3 module, I use this module for ...
1
vote
2answers
97 views

Updating Array Variable In Extending Template

I have a layout template: {% set bodyClass = [] %} <body class="{% for class in bodyClass %}{{ class }} {% endfor %}"> {{ block('pageBody') }} </body> And a template that extends it:...
1
vote
1answer
38 views

SEOmatic and Global Variables

We have a Craft site with nearly 800 entries. For SEO purposes we need to change the page title and page (SEO) description for each entry, a laborious task to say the least. Is there a way to have, ...
1
vote
1answer
105 views

How can I pass a variable defined in a Controller to my variables?

In my Craft 3 plugin I would like to pass a variable defined in my Controller to my PluginVariable.php file. Is this possible?
1
vote
1answer
52 views

Pass last segment to solspace freeform field

Using freeform on another CMS, I was able to pass the last segment of the previous page url (when navigating to the form page) to a form field in the freeform composer, is this feature possible in the ...
2
votes
2answers
429 views

Filter entries by Field value using a variable

How do I filter a list of entries by the value of a field using the value of a variable? e.g. {% set location = block.locationVacancies %} {% set entries = craft.entries.section('careers').search('...
1
vote
1answer
244 views

Twig default filter or Null coalescing operator?

When testing for a variable in a template these two appear to do the same thing. I've read CruftlessCraft's article on How to check for undefined variables but can't see an explanation of why I should ...
1
vote
2answers
44 views

Using variable references to fields in a template

I have a situation where Matrix within Matrix would be ideal, but instead we've ended up with a Matrix row that has pairs of fields up to a maximum of 6: quote1 attribution1 … quoteN attributionN … ...
1
vote
1answer
47 views

stashing variables?

I have an entry id in that I am storing in a variable that I would like to access outside of this for statement, is there a way I can "stash" it somewhere? I want to do another query based on tags but ...
1
vote
1answer
3k views

Twig variables wont work in an include js file?

Im trying to put my code in a included theme.js file. It wont recognize my variables anymore. Working in .rain file within the html code: <script> jQuery(document).ready(function(){ var ...
2
votes
2answers
520 views

How can I iterate through an array of field handles for an entry?

Background: One of my templates has up to 6 fields that should each go into the same markup. Here's an example with a courseDesign field: {% if entry.courseDesign|length %} <section class="col-...
2
votes
1answer
149 views

Specify a field dynamically using section handle

I'm using a single template to display entries from several structures. Each structure has a cooresponding global field that is an entries field. I use this to display related entries as a sidebar. ...
1
vote
1answer
278 views

Passing Querystring Variable to PHP Code in Plugin

I'm pretty new to Craft and PHP, and I am needing to design a page in Craft (powered by a plugin) which will pass a variable in a querystring (or equivalent in Craft) to the PHP code in the plugin. In ...
0
votes
2answers
1k views

Include with — variable does not exist error

New guy here. Can someone explain what the proper way to pass a variable into an include? I'm using this: {% include "singlepage" with { currentPage:'leaders' } %} .. and I'm getting a Variable "...
1
vote
1answer
412 views

How can I access a template variable from an include that is loaded via ajax?

I am making an ajax request to an entry. It is returning the entry's html - and all is working great. I have a section called "portfolio" and I loop through each: portfolio/index.twig {% set ...
2
votes
1answer
151 views

How can I dynamically set checkboxes to be named variables?

If I have a field of checkboxes, I'd like to be able to access them by the name of each checkbox as the variable name, and the 0 or 1 checked state as the value. Said variables need to be accessible ...
1
vote
1answer
835 views

Variable “entry” does not exist

This is very basic as I am new to Craft CMS, but I created a Plain Text field in the Homepage section labeled "Tagline". When I enter the Twig code {{ entry.tagline }} into the index.html template, I ...
1
vote
1answer
756 views

How to get Current Entry ID in Plugin Variable?

I need to get the current entry ID in plugin's variable file without submitting any form. I tried this but it gave an error Undefined property: Craft\PluginNameVariable::$element namespace Craft; ...
1
vote
1answer
87 views

Include Global Set Variable in Print Delimiters

I have a site which has another group site - both use same templates but I want to include different phone number in the header of each. I was wanting to use Global Set Variables to pull this ...
1
vote
2answers
707 views

What is the proper way to set an asset's upload location using the slugs/ structure path of the entry it is selected from?

I'm working on a site with a structure containing products that are nested within "category"(not actually using craft's categories, just an entry type) pages. On each category or sub-category page I ...
1
vote
1answer
329 views

Variable for User Field

How do I go about using a dynamic value to access a user field value? I have created a form builder for users and dynamically populate the user field based on the question's associated field. <...
2
votes
2answers
253 views

Set Craft variables in the markup

I am trying to use Twig methods/loops while working on a design/template. To avoid touching the CP or the DB i did set variables directly in the template, like : {% set service = { 'titel': ...
1
vote
0answers
38 views

Trying to display post based on two variables

I am setting three variables like so ... {% set featureEntryIds = craft.entries({ section: 'blog', featurePost: 1, limit: 1 }).ids() %} {% set articleClass = entry.id in featureEntryIds ? 'featured' ...
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 ...
1
vote
1answer
212 views

craft()->urlManager->setRouteVariables() loads the correct template but does not pass in the variables

everybody! setRouteVariables() doesn't appear to be working for me. If I boil my controller function down to just this: public function actionSubmitForm() { craft()->urlManager->...
1
vote
1answer
87 views

Why two equal variables give false statement?

I have two equal variables comparing each other which give me false. One variable is set out of ancestor entry in structure and another one out of ancestor entry as well. Both variables are set a bit ...
0
votes
1answer
56 views

How to update cart.lineItems while specifying HTTP cache headers?

I use the following cache system, specified in the header of all pages: {% set expiry = now|date_modify('+1 day') %} {% header "Cache-Control: max-age=" ~ expiry.timestamp %} {% header "Pragma: cache"...
1
vote
1answer
428 views

Use variable passed via include to set value of paramenter

I have an include setup for Navigation which works fine if I hard code in the level of the structure I want to use. However I need this to be set differently if the nav appears in the head or the ...
1
vote
2answers
558 views

Test a variable in a set entries tag

I have a page with a featured entry at the top and then remaining entries showing below. On the first {% set entries = craft.entries({ section: 'articles', limit: 1, search: '...
3
votes
1answer
4k views

Pass variable into include

I have a snippet within a template which I want to pass a variable into: page.twig {% set lightswitchTest = entry.aktivesProjekt('1').find() %} {% include '_snippets/thingy' %} thingy.twig <...
1
vote
1answer
395 views

Call a Craft variable inside array

I'm currently trying to call variables called {{entry.title}}, {{entry.latitude}} and so on in an array. This is what it looks like: {% set markerArray = [] %} {% for entry in craft.entries.section('...
1
vote
0answers
90 views

I'm repeatedly setting the same variables. How to reuse code block to make this DRY?

I have a very complex layout which is requiring me to have quite a few {% for %} loops on the page and in each loop I need to set a bunch of variables. In order to make my template more DRY I was ...
2
votes
1answer
152 views

How to shorten 'craft.request.getUrl()' with the shortener plugin?

How can I use the shortener plugin to get and shorten the current URL? I've tried both twig and plugin methods shown in the docs, but the twig method outputs the FULL url, and the plugin method doesn'...
1
vote
1answer
88 views

Reseting variable

I don't even know how I should ask the question. I'll try to explain it as clear as I can. I want to order entries by year-month and output single value (from certain number fields) from all entries ...
2
votes
1answer
384 views

Macros, Variables and Includes

Trying to get my head around this and make my code a little DRYer. I have a _helpers macro file. Like so: {% macro date_formatted(givenDate) %} {{ givenDate|date("l, jS F Y") }} {% endmacro %} {...
1
vote
1answer
65 views

Reusing logic by setting different keywords to create new variables

I need to reuse logic for 15 entry groupings in a template. In my non DRY version, I simply changed one word in the variable name to create a new variable and although it works just fine, it's very ...
4
votes
1answer
175 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: <...
4
votes
1answer
383 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 ...
1
vote
0answers
86 views

How may I restrict uploads to a single folder with variables within a Rich Text Field?

Craft's Asset Fields allow you to restrict uploads to a single folder—and even pass through a variable to create a dynamic path. How may I restrict uploads to a single folder with variables like this ...
1
vote
1answer
934 views

Set a Variable inside a conditional

I'm building my first Craft site and need to set a variable if a field has an image and then use that variable elsewhere in the template. The field is part of a matrix and will repeat. What I have ...
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
85 views

Adding a random entry to an array

I have a navi on which one entry consists of a random channel entry from one section among standard singles: Single 1 Single 2 Random Channel entry Single 3 I thought about something like this: {% ...
2
votes
2answers
473 views

Using a variable with array of ElementIds to use in craft.entries.id

I want to show entries according to an array. This is my code: {% set navsubids = craft.amNav.getNavRaw("hoofdnavigatie", {startFromId:25}) %} {% set navsubidarray = [] %} ...