Monklet Variables

by Chris Ullyott | Last edited: 1/6/2021

Watch Video Tutorial!

Sometimes you might want to use a Monklet to build a layout element, but need to use it repeatedly in various contexts. If only a few values in the Monklet need to be different from one page to another, Monklet Variables eliminate the need to create duplicates.

Monklet variables allow you to define a variable inside the Monklet code itself, where the getContent PHP API provides its value from the frontend. Since the variable receives its value before the Monklet itself is parsed, you can use this to override Monklet settings like "find_category" or "find_group", for example.


In the Monklet, instantiate the variable using double parentheses:


Without further changes, the API has no value to assign to group, so the line including "find_group" is ignored.

To dynamically provide a value to group, an extra parameter "monklet" is added to the API call in the page template. The value of this parameter should be a query string including the name and value of the Monklet variable.

$ministry = 'students';

"find:" . $_GET['nav'],

This API call essentially changes the Monklet to be:



  • Like the PHP API, any Monklet "show" including an undefined ((variable)) will be ignored, and that "show" line will be skipped. This is to avoid returning empty HTML tags.
  • To output the "show" line even when ((variable)) is undefined, you may use ((variable nokill="true")), also similar to the PHP API.
  • You can define multiple variables from the template in two ways. The first is to use one "monklet" parameter in the getContent and concatenate each key-value pair of monklet variables in a query string (the PHP function http_build_query can help with that). The second way is simply to add another "monklet" parameter to the getContent.