@jolie/liquid
v1.0.1
Published
A wrapper for the Liqp Liquid template engine
Downloads
1
Readme
LiquidService
LiquidService is a Jolie service that exposes the rendering API of the Liquid template engine as implemented by the Liqp---plus a few tricks to make it more Jolie-friendly 😉.
Install
jpm add @jolie/liquid
Usage example
from @jolie.liquid.main import Liquid
from console import Console
service main(){
embed Console as Console
embed Liquid as Liquid
main {
template =
"{% case language %}"
+ "{% when 'Danish' %}Hej"
+ "{% when 'French' %}Salut"
+ "{% when 'Italian' %}Ciao"
+ "{% when 'Spanish' %}Hola"
+ "{% when 'Russian' %}привет"
+ "{% when 'Thai' %}สวัสดี"
+ "{% else %}Hi"
+ "{% endcase %}"
+ ", {{ name }}"
data << {
name = "Saverio"
language = "Italian"
}
renderDocument@Liquid({
data << data,
template = template,
format = "jolie"
})( s )
println@Console( s )()
}
}
Jolie Interface
/**
* Loaded templates are useful when sub-templates are necessary
* in the main template (the one used in the renderDocument operation).
* From any template , it is possible to pass data to a loaded template
* with the useTemplate filter, e.g., {{ data | useTemplate: "myTemplate" }}
*/
type LiquidRequest: void {
.data: string | undefined //< either a json string or a jolie value (set accordingly the `format` node)
.format: string( regex( "json|jolie" ) )
.template: string
}
type LoadRequest: void {
.template: string
.name: string
}