To have cleaner, dry code in your shared code block you can do something like this: {% set entry = entry is defined ?: false %} {% set category = category is defined ?: false %} Then your two variables `entry` and `category` will always be defined, which allows you to use very short [ternary syntax][2] in your print expressions. <div class="myDefaultClass{{ entry ? ' myEntryClass' }}"></div> Another thing you could do is to set a new var `model`, which holds either the Entry Model or the Category Model. {% set model = entry is defined ?: category is defined ?: false %} {% set entry = entry is defined ?: false %} {% set category = category is defined ?: false %} <h1>{{ model.title }}</h1> [1]: http://buildwithcraft.com/docs/routing [2]: http://twig.sensiolabs.org/doc/templates.html#other-operators