If Statements with Twig Tests

Last updated

This page is archived

We're keeping this page up as a courtesy to folks who may need to refer to old instructions. We don't plan to update this page.

Alternate resources

Sprout Video

The demo application that corresponds with these videos is out-of-date. The explanations of Twig, and Twig syntax are still correct.

In our last tutorial we have things set up to include a new template, but we are currently getting an error, due to not passing the correct variable. In this tutorial we'll see how to fix this problem by adding a "defined" test to our code, which will check to see if the variable is defined in the _banner.twig template, and default to "lightblue" if it is not.

Additional resources

Twig defined test documentation