mirror of
				https://github.com/smarty-php/smarty.git
				synced 2025-11-04 06:11:37 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			87 lines
		
	
	
		
			2.8 KiB
		
	
	
	
		
			XML
		
	
	
	
	
	
			
		
		
	
	
			87 lines
		
	
	
		
			2.8 KiB
		
	
	
	
		
			XML
		
	
	
	
	
	
<?xml version="1.0" encoding="iso-8859-1"?>
 | 
						|
<!-- $Revision$ -->
 | 
						|
<sect1 id="language.syntax.variables">
 | 
						|
 <title>Variables</title>
 | 
						|
 <para>
 | 
						|
  Template variables start with the $dollar sign. They can contain numbers,
 | 
						|
  letters and underscores, much like a
 | 
						|
  <ulink url="&url.php-manual;language.variables">PHP variable</ulink>.
 | 
						|
  You can reference arrays
 | 
						|
  by index numerically or non-numerically. Also reference
 | 
						|
  object properties and methods.</para>
 | 
						|
  <para>
 | 
						|
  <link linkend="language.config.variables">Config file variables</link>
 | 
						|
  are an exception to the $dollar syntax
 | 
						|
  and are instead referenced with surrounding #hashmarks#, or
 | 
						|
  via the
 | 
						|
  <link linkend="language.variables.smarty.config">
 | 
						|
  <parameter>$smarty.config</parameter></link> variable.
 | 
						|
 </para>
 | 
						|
 <example>
 | 
						|
  <title>Variables</title>
 | 
						|
  <programlisting>
 | 
						|
<![CDATA[
 | 
						|
{$foo}        <-- displaying a simple variable (non array/object)
 | 
						|
{$foo[4]}     <-- display the 5th element of a zero-indexed array
 | 
						|
{$foo.bar}    <-- display the "bar" key value of an array, similar to PHP $foo['bar']
 | 
						|
{$foo.$bar}   <-- display variable key value of an array, similar to PHP $foo[$bar]
 | 
						|
{$foo->bar}   <-- display the object property "bar"
 | 
						|
{$foo->bar()} <-- display the return value of object method "bar"
 | 
						|
{#foo#}       <-- display the config file variable "foo"
 | 
						|
{$smarty.config.foo} <-- synonym for {#foo#}
 | 
						|
{$foo[bar]}   <-- syntax only valid in a section loop, see {section}
 | 
						|
{assign var=foo value='baa'}{$foo} <--  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->bar($baz,2,$bar)} <-- passing parameters
 | 
						|
{"foo"}       <-- static values are allowed
 | 
						|
 | 
						|
{* display the server variable "SERVER_NAME" ($_SERVER['SERVER_NAME'])*}
 | 
						|
{$smarty.server.SERVER_NAME}
 | 
						|
]]>
 | 
						|
  </programlisting>
 | 
						|
 </example>
 | 
						|
 | 
						|
 <para>Request variables such as <literal>$_GET</literal>,
 | 
						|
 <literal>$_SESSION</literal>, etc are available via the
 | 
						|
 reserved <link linkend="language.variables.smarty">
 | 
						|
 <parameter>$smarty</parameter></link> variable.
 | 
						|
 </para>
 | 
						|
 | 
						|
 <para>
 | 
						|
  See also <link linkend="language.variables.smarty">
 | 
						|
  <parameter>$smarty</parameter></link>,
 | 
						|
  <link linkend="language.config.variables">config variables</link>
 | 
						|
  <link linkend="language.function.assign"><varname>{assign}</varname></link>
 | 
						|
  and
 | 
						|
  <link linkend="api.assign"><varname>assign()</varname></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
 | 
						|
-->
 |