-
Notifications
You must be signed in to change notification settings - Fork 7
Crush Templating Engine
Kvantum comes with a custom templating engine, called "Crush". Provided it is enabled, it will be able to act on any text based view/file, before it is sent to the user.
In .kvantum/config/server.yml edit
templates:
engine: !!com.github.intellectualsites.kvantum.api.config.CoreConfig$TemplatingEngine 'CRUSH'Variables are replaced in the text document before served. These are provided by views, but follow a general pattern: {{provider.variable}} where the provider is the service providing the variable. The variables can be complex, such as objects and collections/maps.
Filters can be applied to variables to change their behavior. The name is slightly confusing, as they act more like modifiers. The general pattern is {{provider.variable || FILTER}}. There are a couple of default filters:
-
javascript- Turns the outputted variable into a javascript variable. (Also works for arrays). -
list- If the variable is of a collection type, or an array, it will be outputted using an un-ordered list (<ul>). -
lowercase- Turns the variable into a lowercase string -
uppercase- Turns the variable into an uppercase string
Comments are removed completely from the served document, and so may hold secret data. The pattern is: /* text */
You can loop through a variable if it's either a collection, or array, using a foreach loop. The pattern is: {#foreach provider.variable -> var} ... text... {var} {/foreach}
You can include the content of other files into your file using {{include:file.extension}}
The engine has a built in engine, referred to as meta. Variables can be stored into this using {{: [key: value] :}} and then be referred to using {{meta.key}}
Conditionals can be used to toggle output, either through meta variables or internally.
The pattern is: {#if provider.variable}{/if} and (inverted) {#if !provider.variable}{/if}.
Macros are like functions, that are defined in templates. They are very useful when dealing with repetitive tasks.
A macro is defined by:
{#macro name param1 param2}
<p>{{param1}} said: {{param2}}!</p>
{/macro}
And is then called by:
#name ("value1" "value2")#
Example:
#name ("Trump" "China")#
would output
<p>Trump said: China!</p>Variables can be inserted into macros: {{provider.name}}
IntellectualServer
Files can be found in .kvantum/config
- Getting Started
- View Patterns
- File Patterns
- server.yml
views.yml- socketFilters.yml
- translations.yml
- SSL
- Getting Started
- Modules
- Hello World
- Plugins
- Events
- Account System
- Authorization
- Application System
- Sessions
- Create a view - OOP based
- Create a view - @Annotation based
- Middleware
- Extending Crush (Templating syntax)
- ViewReturn