Files
smarty/docs/en/designers/language-builtin-functions/language-function-php.xml

81 lines
2.2 KiB
XML

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision$ -->
<sect1 id="language.function.php">
<title>{php}</title>
<para>
The <varname>{php}</varname> tags allow PHP code to be embedded directly into the template. They
will not be escaped, regardless of the <link
linkend="variable.php.handling"><parameter>$php_handling</parameter></link> setting. This
is for advanced users only, not normally needed and not recommended.
</para>
<note>
<title>Technical Note</title>
<para>
To access PHP variables in <varname>{php}</varname> blocks you will need to use the PHP
<ulink url="&url.php-manual;global">global</ulink>
keyword.
</para>
</note>
<example>
<title>Example php in {php} tags</title>
<programlisting>
<![CDATA[
{php}
// including a php script directly from the template.
include('/path/to/display_weather.php');
{/php}
]]>
</programlisting>
</example>
<example>
<title>{php} tags with global and assigning a variable</title>
<programlisting role="php">
<![CDATA[
{* this template includes a {php} block that assign's the variable $varX *}
{php}
global $foo, $bar;
if($foo == $bar){
echo 'This will be sent to browser';
}
// assign a variable to Smarty
$this->assign('varX','Toffee');
{/php}
{* output the variable *}
<strong>{$varX}</strong> is my fav ice cream :-)
]]>
</programlisting>
</example>
<para>
See also
<link linkend="variable.php.handling"><parameter>$php_handling</parameter></link>,
<link linkend="language.function.include.php"><varname>{include_php}</varname></link>,
<link linkend="language.function.include"><varname>{include}</varname></link>,
<link linkend="language.function.insert"><varname>{insert}</varname></link>
and
<link linkend="tips.componentized.templates">componentized templates</link>.
</para>
</sect1>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"../../../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->