I'm trying to set a cache duration as an environment variable.
I set up various environment variables and know they are being referenced correctly in my templates because I can print out the values of the variables in my templates.
return array(
'*' => array(
'environmentVariables' => array(
'cacheDuration' => '1 week',
'cacheDurationQuantity' => 1,
'cacheDurationUnit' => 'week',
),
),
);
I initially started with this cache tag...
{% cache for craft.config.environmentVariables.cacheDuration unless craft.config.devMode %}...{% endcache %}
...but I got this error:
Unexpected token "name" of value "craft" ("number" expected)
This had me thinking that perhaps Craft or Twig is expecting an integer immediately after the "for" keyword. Thus, I broke my cacheDuration variable into two parts: quantity which is an integer and unit which is a string.
{% cache for craft.config.environmentVariables.cacheDurationQuantity craft.config.environmentVariables.cacheDurationUnit unless craft.config.devMode %}...{% endcache %}
I still got same error as above. This inspired me to try:
{% set duration = 1 %}
{% cache for duration craft.config.environmentVariables.cacheDurationUnit unless craft.config.devMode %}...{% endcache %}
This time, I got a slightly different error.
Unexpected token "name" of value "duration" ("number" expected)
This has me thinking that any variable evaluated as expected in the duration parameter of the cache tag. However, other variables (like craft.config.devMode) are interpreted fine for other parameters of the cache tag.
Can anyone else confirm this or share insight into this?