Rex's plugins for Construct2
  • Home
  • Map
  • Tutorial/Templates
  • News
  • About

rex_mustache

Plugin, ACE table, Discussion thread
Dependence: None

Introduction
Logic-less templates to render text content. Reference - mustache

Usage
Sample capx
Get render result by "Expression:Render".  It has two input parameters -
  1. Template: a template string for rendering.
  2. View: variables in JSON string
In this sample capx,
  1. The template is "Hello, {{name}}"
  2. The view is {"name":"Construct2"}
Pattern {{name}} in template, will be replaced by the value in view ( i.e. "name" = "Construct2" ), so that the rendering result is "Hello, Construct2".

Use built-in dictionary to store values
Sample capx
The 2nd parameter of "Expression:Render" could be ignored. In this case, this expression will use built-in 1d dictionary to pick the value.
Before rendering, user could set the built-in dictionary by these actions -
  • Action:Clean
  • Action:Set value
Or read value back by "Expression:Value(name)". Add 2nd parameter for default value if this variable does not exist.
Official save/load
The built-in dictionary supports official save/load, or user could get this built-in dictionary by "Expression:VariablesAsJSON", then load it by "Action:Load from JSON"

Set delimiters
Sample capx
Left and right delimiters could be changed. Set delimiters in properties "Left delimiter", "Right delimiter", or set by "Action:Set delimiters".

Create a free web site with Weebly
  • Home
  • Map
  • Tutorial/Templates
  • News
  • About