Site:Frontend:Macros
From Metrixstream
Revision as of 11:27, 15 June 2012 by MetrixJustin (Talk | contribs)
Introduction
Macros are the Clearsilver equivalent to functions. Macros let you define a block of code that can be re-used throughout the site.
Creating a Macro
Macros are made by starting and ending a new clearsilver block with def.
<?cs def:getUsername() ?> <?cs var:MS.site.auth.username ?> <?cs /def ?>
With macros there is no returning specific data, anything in the macro will be placed where its called.
Macro Parameters
You can pass parameters into the macro by setting them after the macro name
<?cs def:getUsername(user) ?> <?cs var:user.username ?> <?cs /def ?>
This macro requires the user parameter to generate the username.