Adds support for Mustache Tags in Rapid Weaver / Stacks.
Why "Mustache"? Because the curly brackets look like a mustache 😎
⚠️ Mustache requires very basic PHP knowledge and PHP Hosting!
Global Values for the whole RapidWeaver project centralized:
This is the main stack for Mustache content templating and processing. All stacks placed inside the Mustache stack will be processed. Every occurence of a placeholder (a variable name / key enclosed with double curly brackets, "{{placeholder}}
") is replaced with the corresponding value from the data file. This includes also values in the Stack inspector for stacks placed inside the Mustache stack.
All processing is done on the server.
Requried:
A Mustache Stack is a "Template" and all occurences of Mustache Tags / placeholders ({{placeholder}}
) inside this stack will be replaced with the corresponding value from the configured data file and array.
Place a Mustache stack on the page. Open the inspector and look for the Configuration section. Use the page selector "Key/Value File" to select a data file, this can be either a page containng a Mustacha Data
stack or plain data file.
If you have specified a different array name other than values
, enter the array name into "Value Array". The array name must match the array name you specified in the data pages / data files.
The Debug Setting "Show Values" will ad a button to the page which will show the data of the given array. This comes handy when the page doesn't show up all values as expected.
The Mustache Data
stack is a convenient way to create global data for your site. Just create a empty Stacks page, add one or more Mustache Data
stacks and populate your required data. Configure a Mustache
stack to link to your data page.
Mustache Data
doesn't support nesting, for more advanced usage, create a plain data file.Mustache Date
supports expression values only on data generation. If you need dynamic expressions, create a plain data file (see below)..html
to .php
.$values
, here's an example:<?php
$values = [
"firstname" => "Heiko",
"lastname" => "Kanzer",
];
?>
Note:
key
is the left part before the arrow.-
) and underscores (_
) are allowed.Mustache Raw Stack
). If you want to use quotes in the value, you have to add a \
(aka "escaping") before each quote, otherwise you break the code: "Hello World"
becomes \"Hello World\"
Mustache Section
stack for an advanced example)For a better organisation, you can "nest" the values:
<?php
$values = [
"person" => [
"firstname" => "Heiko",
"lastname" => "Kanzler",
],
];
?>
Access the nested data via "dot notation": {{person.firstname}}
The Mustache Section
Helper Stack has two powerfull features:
The stack can hide content placed in its drop zone if a specified key is set to false
, e.g. "show_intro" => false,
or show the content if set to true
.
If you set the value of the key to someting like "show_text" => $_GET['show'] == "true" ? true : false,
, you can disable / enable the content by appending ?show=true
or ?show=false
to the page url.
If the given key coontains a sub-array of key/value pairs, Mustache Section
automatically repeats the stacks for each occurence in this sub-array. This allows to loop over predefined data.
Example:
This defines a array people
inside the main data array, containing four sub-arrays with user data.
<?php
$values = [
"people" => [
[
"username" => "Anna",
"profile_image" => "../resources/profile_images/user1",
"profession" => "Key Account Manager",
"location" => "Madrid",
] ,
[
"username" => "Markus",
"profile_image" => "../resources/profile_images/user2",
"profession" => "Sales Executive",
"location" => "Berlin",
] ,
[
"username" => "Debbie",
"profile_image" => "../resources/profile_images/user3",
"profession" => "Team Lead",
"location" => "Gibraltar",
] ,
[
"username" => "François",
"profile_image" => "../resources/profile_images/user4",
"profession" => "liaison Manager",
"location" => "Paris",
] ,
],
];
?>
Setting the key of the Mustache Section
stack to people
now iterates / loops over all elements of the people
: All stacks placed inside the Mustache Section
will be rendered four times, each with the data of a single person (see also Mustache Profiles Demo)
The output will look like this:
The Mustache Raw
helper stack renders the value of the given key as raw html.
,
after each key value pair"
to \"
)=>
are misspelled
Download version 1.0 and a demo file.
You need the free Paper theme by Theme Flood