Site:Frontend:Macros

From Metrixstream
(Difference between revisions)
Jump to: navigation, search
(Creating a Macro)
(Introduction)
Line 2: Line 2:
  
 
Macros are the Clearsilver equivalent to functions. Macros let you define a block of code that can be re-used throughout the site.
 
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 ===
 
=== Creating a Macro ===

Revision as of 12:54, 15 June 2012

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.

Personal tools