This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

that0n3guy
that0n3guy

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.

that0n3guy
pikusfikus
Cpt.Meatball
Cpt.Meatball

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

Sebastian Hilger
Sebastian Hilger

Up. I have the same problem - I am not checking if it has content, I would like to check if the variable ist set.

Kaybee
kh_october13612
kh_october13612
{% 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

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.