Get Smarty

Smarty Icon

You may use the Smarty logo according to the trademark notice.

Smarty Template Engine Smarty Template Engine

For sponsorship, advertising, news or other inquiries, contact us at:

Check reviews of PHP Web Hosting, compatible with Smarty Templates

{call}

{call} is used to call a template function defined by the {function} tag just like a plugin function.

Note

Template functions are defined global. Since the Smarty compiler is a single-pass compiler, The {call} tag must be used to call a template function defined externally from the given template. Otherwise you can directly use the function as {funcname ...} in the template.

  • The {call} tag must have the name attribute which contains the the name of the template function.

  • Values for variables can be passed to the template function as attributes.

Attributes:

Attribute Name Type Required Default Description
name string Yes n/a The name of the template function
assign string No n/a The name of the variable that the output of called template function will be assigned to
[var ...] [var type] No n/a variable to pass local to template function

Option Flags:

Name Description
nocache Call the template function in nocache mode

Example 7.20. Calling a recursive menu example


{* define the function *}
{function name=menu level=0}
  <ul class="level{$level}">
  {foreach $data as $entry}
    {if is_array($entry)}
      <li>{$entry@key}</li>
      {call name=menu data=$entry level=$level+1}
    {else}
      <li>{$entry}</li>
    {/if}
  {/foreach}
  </ul>
{/function}

{* create an array to demonstrate *}
{$menu = ['item1','item2','item3' => ['item3-1','item3-2','item3-3' =>
['item3-3-1','item3-3-2']],'item4']}

{* run the array through the function *}
{call name=menu data=$menu}
{call menu data=$menu} {* short-hand *}

  

Will generate the following output


* item1
* item2
* item3
      o item3-1
      o item3-2
      o item3-3
            + item3-3-1
            + item3-3-2
* item4

  

See also {function}

Comments
No comments for this page.
Post a Comment
All comments are moderated. Support questions are ignored, use the forums instead.
Author:
Email: (not shown)
What is 2 plus 1? (Are you human?)

Sponsors [info]

Cheap Website Hosting @hostdone.com
email marketing @ActiveCampaign
broadband deals @BroadbandGenie
Best UK Web Hosting @webhost.uk.net
Reliable UK and US Web Hosting @rshosting.com
Cheap US and UK Web Hosting @infrenion.com
I.T Certification Exams @pass-guaranteed.com
Certification Practice Tests @firsttrycertify.com
Certification Practice Exam Questions @ace-it-certifications.com
Broadband Speed Test @broadbandspeed.co.uk
bulk email software @americaint.com
ASP.NET hosting @aspnethosting.co.uk