<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Embedding Vars in Double Quotes</title> <meta name="generator" content="DocBook XSL Stylesheets V1.75.1"> <link rel="home" href="index.html" title="Smarty Manual"> <link rel="up" href="language.basic.syntax.html" title="Chapter 3. Basic Syntax"> <link rel="prev" href="language.syntax.attributes.html" title="Attributes"> <link rel="next" href="language.math.html" title="Math"> </head> <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> <div class="navheader"> <table width="100%" summary="Navigation header"> <tr><th colspan="3" align="center">Embedding Vars in Double Quotes</th></tr> <tr> <td width="20%" align="left"> <a accesskey="p" href="language.syntax.attributes.html">Prev</a> </td> <th width="60%" align="center">Chapter 3. Basic Syntax</th> <td width="20%" align="right"> <a accesskey="n" href="language.math.html">Next</a> </td> </tr> </table> <hr> </div> <div class="sect1" title="Embedding Vars in Double Quotes"> <div class="titlepage"><div><div><h2 class="title" style="clear: both"> <a name="language.syntax.quotes"></a>Embedding Vars in Double Quotes</h2></div></div></div> <div class="itemizedlist"><ul class="itemizedlist" type="disc"> <li class="listitem"><p> Smarty will recognize <a class="link" href="api.assign.html" title="assign()">assigned</a> <a class="link" href="language.syntax.variables.html" title="Variables">variables</a> embedded in "double quotes" so long as the variable name contains only numbers, letters, under_scores and brackets[]. See <a class="ulink" href="http://php.net/language.variables" target="_top">naming</a> for more detail. </p></li> <li class="listitem"><p> With any other characters, for example a .period or <code class="literal">$object>reference</code>, then the variable must be surrounded by <code class="literal">`backticks`</code>. </p></li> <li class="listitem"><p>You cannot embed <a class="link" href="language.modifiers.html" title="Chapter 5. Variable Modifiers">modifiers</a>, they must always be applied outside of quotes. </p></li> </ul></div> <div class="example"> <a name="id3028364"></a><p class="title"><b>Example 3.5. Syntax examples</b></p> <div class="example-contents"><pre class="programlisting"> {func var="test $foo test"} <-- sees $foo {func var="test $foo_bar test"} <-- sees $foo_bar {func var="test $foo[0] test"} <-- sees $foo[0] {func var="test $foo[bar] test"} <-- sees $foo[bar] {func var="test $foo.bar test"} <-- sees $foo (not $foo.bar) {func var="test `$foo.bar` test"} <-- sees $foo.bar {func var="test `$foo.bar` test"|escape} <-- modifiers outside quotes! </pre></div> </div> <br class="example-break"><div class="example"> <a name="id3028376"></a><p class="title"><b>Example 3.6. Practical examples</b></p> <div class="example-contents"><pre class="programlisting"> {* will replace $tpl_name with value *} {include file="subdir/$tpl_name.tpl"} {* doesn't replace $tpl_name *} {include file='subdir/$tpl_name.tpl'} <-- {* must have backticks as it contains a . *} {cycle values="one,two,`$smarty.config.myval`"} {* same as $module['contact'].'.tpl' in a php script {include file="`$module.contact`.tpl"} {* same as $module[$view].'.tpl' in a php script {include file="`$module.$view`.tpl"} </pre></div> </div> <br class="example-break"><p> See also <a class="link" href="language.modifier.escape.html" title="escape"><code class="varname">escape</code></a>. </p> </div> <div class="navfooter"> <hr> <table width="100%" summary="Navigation footer"> <tr> <td width="40%" align="left"> <a accesskey="p" href="language.syntax.attributes.html">Prev</a> </td> <td width="20%" align="center"><a accesskey="u" href="language.basic.syntax.html">Up</a></td> <td width="40%" align="right"> <a accesskey="n" href="language.math.html">Next</a> </td> </tr> <tr> <td width="40%" align="left" valign="top">Attributes </td> <td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td> <td width="40%" align="right" valign="top"> Math</td> </tr> </table> </div> </body> </html>