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

84 lines
2.1 KiB
XML
Raw Normal View History

2004-04-13 08:46:28 +00:00
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision$ -->
2005-05-10 20:54:42 +00:00
<sect1 id="language.function.php">
<title>{php}</title>
2005-05-10 20:54:42 +00:00
<para>
2006-03-28 01:15:34 +00:00
The {php} tags allow PHP code to be embedded directly into the template. They
2005-05-10 20:54:42 +00:00
will not be escaped, regardless of the <link
linkend="variable.php.handling">$php_handling</link> setting. This
2006-03-28 01:15:34 +00:00
is for advanced users only, not normally needed and not recommended.
2005-05-10 20:54:42 +00:00
</para>
<example>
2005-05-27 16:25:02 +00:00
<title>{php} tags</title>
2006-03-28 01:15:34 +00:00
<programlisting>
2005-05-10 20:54:42 +00:00
<![CDATA[
2005-05-27 16:25:02 +00:00
{php}
2005-05-10 20:54:42 +00:00
// including a php script directly
// from the template.
include('/path/to/display_weather.php');
2005-05-27 16:25:02 +00:00
{/php}
2005-05-10 20:54:42 +00:00
]]>
</programlisting>
</example>
2005-05-27 16:25:02 +00:00
<note>
<title>Technical Note</title>
<para>
To access PHP variables in {php} blocks you may need to use the PHP
<ulink url="&url.php-manual;global">global</ulink>
keyword.
</para>
</note>
<example>
2006-03-28 01:15:34 +00:00
<title>{php} tags with global and assigning a variable</title>
<programlisting role="php">
<![CDATA[
{php}
global $foo, $bar;
if($foo == $bar){
2006-03-28 01:15:34 +00:00
echo 'This will come out in the template';
}
2006-03-28 01:15:34 +00:00
$this->assign('varX','Strawberry');
{/php}
2006-03-28 01:15:34 +00:00
<strong>{$varX}</strong> is my fav ice cream
]]>
</programlisting>
2006-03-28 01:23:16 +00:00
<para>The following seriously NOT recommended as its in the template scope</para>
<programlisting
<![CDATA[
{php}
print_r($some_array);
{/php}
]]>
</programlisting>
</example>
2005-05-10 20:54:42 +00:00
<para>
See also
<link linkend="variable.php.handling">$php_handling</link>,
2005-05-10 20:54:42 +00:00
<link linkend="language.function.include.php">{include_php}</link>,
2006-02-17 22:19:14 +00:00
<link linkend="language.function.include">{include}</link>,
<link linkend="language.function.insert">{insert}</link> and
2005-05-10 20:54:42 +00:00
<link linkend="tips.componentized.templates">Componentized Templates</link>.
</para>
2004-04-13 08:46:28 +00:00
</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
-->