# Tips & Tricks ## Blank Variable Handling There may be times when you want to print a default value for an empty variable instead of printing nothing, such as printing ` ` so that html table backgrounds work properly. Many would use an [`{if}`](../designers/language-builtin-functions/language-function-if.md) statement to handle this, but there is a shorthand way with Smarty, using the [`default`](../designers/language-modifiers/language-modifier-default.md) variable modifier. > **Note** > > "Undefined variable" errors will show an E\_NOTICE if not disabled in > PHP's [`error_reporting()`](https://www.php.net/error_reporting) level or > Smarty's [`$error_reporting`](../programmers/api-variables/variable-error-reporting.md) property and > a variable had not been assigned to Smarty. ```smarty {* the long way *} {if $title eq ''} {else} {$title} {/if} {* the short way *} {$title|default:' '} ``` See also [`default`](../designers/language-modifiers/language-modifier-default.md) modifier and [default variable handling](#default-variable-handling). ## Default Variable Handling If a variable is used frequently throughout your templates, applying the [`default`](../designers/language-modifiers/language-modifier-default.md) modifier every time it is mentioned can get a bit ugly. You can remedy this by assigning the variable its default value with the [`{assign}`](../designers/language-builtin-functions/language-function-assign.md) function. {* do this somewhere at the top of your template *} {assign var='title' value=$title|default:'no title'} {* if $title was empty, it now contains the value "no title" when you use it *} {$title} See also [`default`](../designers/language-modifiers/language-modifier-default.md) modifier and [blank variable handling](#blank-variable-handling). ## Passing variable title to header template When the majority of your templates use the same headers and footers, it is common to split those out into their own templates and [`{include}`](../designers/language-builtin-functions/language-function-include.md) them. But what if the header needs to have a different title, depending on what page you are coming from? You can pass the title to the header as an [attribute](../designers/language-basic-syntax/language-syntax-attributes.md) when it is included. `mainpage.tpl` - When the main page is drawn, the title of "Main Page" is passed to the `header.tpl`, and will subsequently be used as the title. ```smarty {include file='header.tpl' title='Main Page'} {* template body goes here *} {include file='footer.tpl'} ``` `archives.tpl` - When the archives page is drawn, the title will be "Archives". Notice in the archive example, we are using a variable from the `archives_page.conf` file instead of a hard coded variable. ```smarty {config_load file='archive_page.conf'} {include file='header.tpl' title=#archivePageTitle#} {* template body goes here *} {include file='footer.tpl'} ``` `header.tpl` - Notice that "Smarty News" is printed if the `$title` variable is not set, using the [`default`](../designers/language-modifiers/language-modifier-default.md) variable modifier. ```smarty