Built-capture function of Smarty

The role of capture are:

   Output template data capture and stored in a variable, rather than outputs them to the page, in any {capture name = "foo"} between the data and {/ capture} is stored in the variable $ foo, the attribute specified by the variable name, by accessing the template variable $ smarty.capture.foo, {capture} must be paired, i.e. {/ capture} as the end, the function can not be nested, Capture has two attributes: name and assignassign;

  Example:

  The first case: the use of the name attribute

  {capture name='color'}red{/capture}
  {$smarty.capture.color} 

  The second case: using assign, capturing content to a variable

  {capture assign='foo'}blue{/capture}
  {$foo}

  The third case: Using append, to capture the contents of an array

  {capture append='arr'}abs{/capture}
  {capture append='arr'}zks{/capture}
  {foreach $arr as $val}{$val}<br>{/foreach}

 

Guess you like

Origin www.cnblogs.com/cmszzk/p/11241584.html