Stacey2
Templating Language
Stacey pre-parses each template as plain text before it is rendered out as html. As the templating system runs off regular expressions, there is no need to explicitly wrap the language constructs in <?php ?>
tags.
Language Constructs
Within stacey templates, you have access to three language constructs: get statements, foreach loops and boolean if statements.
- get
-
get "/projects"
- foreach
-
foreach $collection do # do stuff endforeach
- if
-
if @variable do # do stuff endif
- if not
-
if !@variable do # do stuff endif
Variable Context
Once you are inside a foreach loop, the variable context changes to the current object being referenced by the loop. So in the above example, we are accessing the @url and @page_name variables for each page being looped over.
If you want to shift to the context of a specific page, you can add a get call to the top of your partial or template.
get "/projects"
This will change the context from the current page being viewed to the /projects page. This means $children will be filled with the children of the /projects page, @page_name will equal 'Projects', etc.
So, if you wanted to only list children of the /projects folder which do not contain children of their own, you could construct the following partial:
get "/projects" foreach $children do if !$children do <p><a href="@url">@page_name</a></p> endif endforeach
Nesting foreach Loops
To give you the ability to pass through a multiple levels of objects, foreach loops can also be nested within themselves (although using recursive partials is a much cleaner way of doing this).
<ol id="navigation"> foreach $root do <li><a href="@url">@page_name</a> if $children do <ol> foreach $children do <li><a href="@url">@page_name</a> endforeach </ol> endif </li> endforeach </ol>