Sophie

Sophie

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

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

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>{include_php}</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.builtin.functions.html" title="Chapter 7. Built-in Functions">
<link rel="prev" href="language.function.include.html" title="{include}">
<link rel="next" href="language.function.insert.html" title="{insert}">
</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">{include_php}</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="language.function.include.html">Prev</a> </td>
<th width="60%" align="center">Chapter 7. Built-in Functions</th>
<td width="20%" align="right"> <a accesskey="n" href="language.function.insert.html">Next</a>
</td>
</tr>
</table>
<hr>
</div>
<div class="sect1" title="{include_php}">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="language.function.include.php"></a>{include_php}</h2></div></div></div>
<div class="note" title="Technical Note" style="margin-left: 0.5in; margin-right: 0.5in;">
<h3 class="title">Technical Note</h3>
<p>
    <code class="varname">{include_php}</code> is pretty much deprecated from Smarty, you can
    accomplish the same functionality via a custom template function.
    The only reason to use <code class="varname">{include_php}</code> is if you really have a need to
    quarantine the php function away from the
    <a class="link" href="variable.plugins.dir.html" title="$plugins_dir"><code class="filename">plugins/</code></a>
    directory or your
    application code. See the <a class="link" href="tips.componentized.templates.html" title="Componentized Templates">componentized template
    example</a> for details.
   </p>
</div>
<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">file</td>
<td align="center">string</td>
<td align="center">Yes</td>
<td align="center"><span class="emphasis"><em>n/a</em></span></td>
<td>The name of the php file to include</td>
</tr>
<tr>
<td align="center">once</td>
<td align="center">boolean</td>
<td align="center">No</td>
<td align="center"><span class="emphasis"><em><code class="constant">TRUE</code></em></span></td>
<td>whether or not to include the php file more than
      once if included multiple times</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 name of the variable that the output of
      include_php will be assigned to</td>
</tr>
</tbody>
</table></div>
<p>
  <code class="varname">{include_php}</code> tags are used to include a php script in your template.
  If <a class="link" href="variable.security.html" title="$security"><em class="parameter"><code>$security</code></em></a> is enabled,
  then the php script must be located in the <a class="link" href="variable.trusted.dir.html" title="$trusted_dir"><em class="parameter"><code>$trusted_dir</code></em></a> path.
  The <code class="varname">{include_php}</code> tag must have the attribute
  <em class="parameter"><code>file</code></em>, which contains the path to the included php file, either
  relative to  <a class="link" href="variable.trusted.dir.html" title="$trusted_dir"><em class="parameter"><code>$trusted_dir</code></em></a>,
  or an absolute path.
 </p>
<p>
  By default, php files are only included once even if called
  multiple times in the template. You can specify that it should be
  included every time with the <em class="parameter"><code>once</code></em> attribute.
  Setting once to <code class="constant">FALSE</code> will include the php script each time it is
  included in the template.
 </p>
<p>
  You can optionally pass the <em class="parameter"><code>assign</code></em> attribute,
  which will specify a template variable name that the output of
  <code class="varname">{include_php}</code> will be assigned to instead of
  displayed.
 </p>
<p>
  The smarty object is available as <em class="parameter"><code>$this</code></em> within
  the PHP script that you include.
 </p>
<div class="example">
<a name="id3052144"></a><p class="title"><b>Example 7.21. function {include_php}</b></p>
<div class="example-contents">
<p>The <code class="filename">load_nav.php</code> file:</p>
<pre class="programlisting">

&lt;?php

// load in variables from a mysql db and assign them to the template
require_once('database.class.php');
$db = new Db();
$db-&gt;query('select url, name from navigation order by name');
$this-&gt;assign('navigation', $db-&gt;getRows());

?&gt;

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

{* absolute path, or relative to $trusted_dir *}
{include_php file='/path/to/load_nav.php'}

{foreach item='nav' from=$navigation}
  &lt;a href="{$nav.url}"&gt;{$nav.name}&lt;/a&gt;&lt;br /&gt;
{/foreach}

  </pre>
</div>
</div>
<br class="example-break"><p>
  See also <a class="link" href="language.function.include.html" title="{include}"><code class="varname">{include}</code></a>,
  <a class="link" href="variable.security.html" title="$security"><em class="parameter"><code>$security</code></em></a>,
<a class="link" href="variable.trusted.dir.html" title="$trusted_dir"><em class="parameter"><code>$trusted_dir</code></em></a>,
  <a class="link" href="language.function.php.html" title="{php}"><code class="varname">{php}</code></a>, <a class="link" href="language.builtin.functions.html#language.function.capture" title="{capture}"><code class="varname">{capture}</code></a>, <a class="link" href="template.resources.html" title="Resources">template resources</a> and <a class="link" href="tips.componentized.templates.html" title="Componentized Templates">componentized templates</a> </p>
</div>
<div class="navfooter">
<hr>
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="language.function.include.html">Prev</a> </td>
<td width="20%" align="center"><a accesskey="u" href="language.builtin.functions.html">Up</a></td>
<td width="40%" align="right"> <a accesskey="n" href="language.function.insert.html">Next</a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">{include} </td>
<td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td>
<td width="40%" align="right" valign="top"> {insert}</td>
</tr>
</table>
</div>
</body>
</html>