Sophie

Sophie

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

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

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>{eval}</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.custom.functions.html" title="Chapter 8. Custom Functions">
<link rel="prev" href="language.function.debug.html" title="{debug}">
<link rel="next" href="language.function.fetch.html" title="{fetch}">
</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">{eval}</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="language.function.debug.html">Prev</a> </td>
<th width="60%" align="center">Chapter 8. Custom Functions</th>
<td width="20%" align="right"> <a accesskey="n" href="language.function.fetch.html">Next</a>
</td>
</tr>
</table>
<hr>
</div>
<div class="sect1" title="{eval}">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="language.function.eval"></a>{eval}</h2></div></div></div>
<p>
   <code class="varname">{eval}</code> is used to evaluate a variable as a template.
   This can be used  for things like embedding template tags/variables into
   variables or  tags/variables into config file variables.
  </p>
<p>
   If you supply the <em class="parameter"><code>assign</code></em> attribute, the output of the
   <code class="varname">{eval}</code> function will be assigned to this template
    variable instead of  being output to the template.
 </p>
<div class="informaltable"><table border="1">
<colgroup>
<col align="center">
<col align="center">
<col align="center">
<col align="center">
<col>
</colgroup>
<thead><tr>
<th align="center">Attribute Name</th>
<th align="center">Type</th>
<th align="center">Required</th>
<th align="center">Default</th>
<th>Description</th>
</tr></thead>
<tbody>
<tr>
<td align="center">var</td>
<td align="center">mixed</td>
<td align="center">Yes</td>
<td align="center"><span class="emphasis"><em>n/a</em></span></td>
<td>Variable (or string) to evaluate</td>
</tr>
<tr>
<td align="center">assign</td>
<td align="center">string</td>
<td align="center">No</td>
<td align="center"><span class="emphasis"><em>n/a</em></span></td>
<td>The template variable the output will be assigned
      to</td>
</tr>
</tbody>
</table></div>
<div class="note" title="Technical Note" style="margin-left: 0.5in; margin-right: 0.5in;">
<h3 class="title">Technical Note</h3>
<p>
  </p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem"><p>
   Evaluated variables are treated the same as templates. They follow
   the same escapement and security features just as if they were
   templates.
  </p></li>
<li class="listitem"><p>
   Evaluated variables are compiled on every invocation, the compiled
   versions are not saved! However if you have
   <a class="link" href="caching.html" title="Chapter 14. Caching">caching</a>   enabled, the
   output will be cached with the rest of the template.
  </p></li>
</ul></div>
<p>
  </p>
</div>
<div class="example">
<a name="id3066562"></a><p class="title"><b>Example 8.6. {eval}</b></p>
<div class="example-contents">
<p>The contents of the config file, <code class="filename">setup.conf</code>.</p>
<pre class="programlisting">

emphstart = &lt;strong&gt;
emphend = &lt;/strong&gt;
title = Welcome to {$company}'s home page!
ErrorCity = You must supply a {#emphstart#}city{#emphend#}.
ErrorState = You must supply a {#emphstart#}state{#emphend#}.

  </pre>
<p>
   Where the template is:
  </p>
<pre class="programlisting">

{config_load file='setup.conf'}

{eval var=$foo}
{eval var=#title#}
{eval var=#ErrorCity#}
{eval var=#ErrorState# assign='state_error'}
{$state_error}

  </pre>
<p>
   The above template will output:
  </p>
<pre class="screen">

This is the contents of foo.
Welcome to Foobar Pub &amp; Grill's home page!
You must supply a &lt;strong&gt;city&lt;/strong&gt;.
You must supply a &lt;strong&gt;state&lt;/strong&gt;.

  </pre>
</div>
</div>
<br class="example-break"><div class="example">
<a name="id3066616"></a><p class="title"><b>Example 8.7. Another {eval} example</b></p>
<div class="example-contents">
<p>This outputs the server name (in uppercase)  and IP. The assigned
   variable <em class="parameter"><code>$str</code></em> could be from a database query.</p>
<pre class="programlisting">
 
&lt;?php
$str = 'The server name is {$smarty.server.SERVER_NAME|upper} '
       .'at {$smarty.server.SERVER_ADDR}';
$smarty-&gt;assign('foo',$str);
?&gt;
 
   </pre>
<p>
    Where the template is:
   </p>
<pre class="programlisting">
 
    {eval var=$foo}
 
   </pre>
</div>
</div>
<br class="example-break">
</div>
<div class="navfooter">
<hr>
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="language.function.debug.html">Prev</a> </td>
<td width="20%" align="center"><a accesskey="u" href="language.custom.functions.html">Up</a></td>
<td width="40%" align="right"> <a accesskey="n" href="language.function.fetch.html">Next</a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">{debug} </td>
<td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td>
<td width="40%" align="right" valign="top"> {fetch}</td>
</tr>
</table>
</div>
</body>
</html>