This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
I have something like:
{% if viewBag.smallTitle is defined %}
<small>{{ viewBag.smallTitle }}</small>
{% endif %}
This doesn't work. If smallTitle
is NOT set, I get an error:
An exception has been thrown during the rendering of a template ("The component 'Cms\Classes\ViewBag' does not contain a method 'smallTitle'.").
This error points to <small>{{ viewBag.smallTitle }}</small>
. So twig is getting past the if statement... even thought its not defined.
Are you checking for it to have content? Because if you have this (pseudo)code:
viewBag[smalltitle] = getTitlefromDB();
If it returns null
the variable is still set, but it doesn't have any content. Perhaps twig doesn't like null
. You could try to something like this:
if(getTitlefromDB())
//fill viewbag variable
Last updated
Up. I have the same problem - I am not checking if it has content, I would like to check if the variable ist set.
Maybe you want to be using attribute in twig? http://twig.sensiolabs.org/doc/functions/attribute.html
{% if viewBag.smallTitle is defined %}
The exception says smallTitle is a method. It is not defined.
I am checking it this way.
{% if viewBag.property("smallTitle") %}
It seems to work. But not sure this is the right way.
Last updated
1-7 of 7