Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > 3ca7e0e5486da714e98ac79af09ca745 > files > 117

php-smarty2-doc-2.6.28-2.mga4.noarch.rpm

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Variables</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.basic.syntax.html" title="Chapter 3. Basic Syntax">
<link rel="next" href="language.syntax.functions.html" title="Functions">
</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">Variables</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="language.basic.syntax.html">Prev</a> </td>
<th width="60%" align="center">Chapter 3. Basic Syntax</th>
<td width="20%" align="right"> <a accesskey="n" href="language.syntax.functions.html">Next</a>
</td>
</tr>
</table>
<hr>
</div>
<div class="sect1" title="Variables">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="language.syntax.variables"></a>Variables</h2></div></div></div>
<p>
  Template variables start with the $dollar sign. They can contain numbers,
  letters and underscores, much like a
  <a class="ulink" href="http://php.net/language.variables" target="_top">PHP variable</a>.
  You can reference arrays
  by index numerically or non-numerically. Also reference
  object properties and methods.</p>
<p>
  <a class="link" href="language.config.variables.html" title="Variables loaded from config files">Config file variables</a>
  are an exception to the $dollar syntax
  and are instead referenced with surrounding #hashmarks#, or
  via the
  <a class="link" href="language.variables.smarty.html#language.variables.smarty.config" title="{$smarty.config}">
  <em class="parameter"><code>$smarty.config</code></em></a> variable.
 </p>
<div class="example">
<a name="id3026799"></a><p class="title"><b>Example 3.2. Variables</b></p>
<div class="example-contents"><pre class="programlisting">

{$foo}        &lt;-- displaying a simple variable (non array/object)
{$foo[4]}     &lt;-- display the 5th element of a zero-indexed array
{$foo.bar}    &lt;-- display the "bar" key value of an array, similar to PHP $foo['bar']
{$foo.$bar}   &lt;-- display variable key value of an array, similar to PHP $foo[$bar]
{$foo-&gt;bar}   &lt;-- display the object property "bar"
{$foo-&gt;bar()} &lt;-- display the return value of object method "bar"
{#foo#}       &lt;-- display the config file variable "foo"
{$smarty.config.foo} &lt;-- synonym for {#foo#}
{$foo[bar]}   &lt;-- syntax only valid in a section loop, see {section}
{assign var=foo value='baa'}{$foo} &lt;--  displays "baa", see {assign}

Many other combinations are allowed

{$foo.bar.baz}
{$foo.$bar.$baz}
{$foo[4].baz}
{$foo[4].$baz}
{$foo.bar.baz[4]}
{$foo-&gt;bar($baz,2,$bar)} &lt;-- passing parameters
{"foo"}       &lt;-- static values are allowed

{* display the server variable "SERVER_NAME" ($_SERVER['SERVER_NAME'])*}
{$smarty.server.SERVER_NAME}

  </pre></div>
</div>
<br class="example-break"><p>Request variables such as <code class="literal">$_GET</code>,
 <code class="literal">$_SESSION</code>, etc are available via the
 reserved <a class="link" href="language.variables.smarty.html" title="{$smarty} reserved variable">
 <em class="parameter"><code>$smarty</code></em></a> variable.
 </p>
<p>
  See also <a class="link" href="language.variables.smarty.html" title="{$smarty} reserved variable">
  <em class="parameter"><code>$smarty</code></em></a>,
  <a class="link" href="language.config.variables.html" title="Variables loaded from config files">config variables</a>
  <a class="link" href="language.custom.functions.html#language.function.assign" title="{assign}"><code class="varname">{assign}</code></a>
  and
  <a class="link" href="api.assign.html" title="assign()"><code class="varname">assign()</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.basic.syntax.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.syntax.functions.html">Next</a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">Chapter 3. Basic Syntax </td>
<td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td>
<td width="40%" align="right" valign="top"> Functions</td>
</tr>
</table>
</div>
</body>
</html>