Site:Frontend:Macros

From Metrixstream
(Difference between revisions)
Jump to: navigation, search
(Introduction)
(Introduction)
 
Line 1: Line 1:
 
=== Introduction ===
 
=== Introduction ===
  
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.... almost. They only produce output to the browser rather than supplying a return value. Because of this the term macro is a more suitable name.
 +
Macros let you define a block of code that can be re-used throughout the site.
  
 
=== Creating a Macro ===
 
=== Creating a Macro ===

Latest revision as of 10:22, 20 June 2012

[edit] Introduction

Macros are the Clearsilver equivalent to functions.... almost. They only produce output to the browser rather than supplying a return value. Because of this the term macro is a more suitable name. Macros let you define a block of code that can be re-used throughout the site.

[edit] 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.

[edit] 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