Crates.io | liquid |
lib.rs | liquid |
version | 0.26.9 |
source | src |
created_at | 2015-02-15 14:08:55.05311 |
updated_at | 2024-08-01 18:49:29.856751 |
description | The liquid templating language for Rust |
homepage | |
repository | https://github.com/cobalt-org/liquid-rust |
max_upload_size | |
id | 1408 |
size | 61,217 |
Liquid templating for Rust
Goals:
Example applications using liquid-rust:
To include liquid in your project add the following to your Cargo.toml:
$ cargo add liquid
Example:
let template = liquid::ParserBuilder::with_stdlib()
.build().unwrap()
.parse("Liquid! {{num | minus: 2}}").unwrap();
let mut globals = liquid::object!({
"num": 4f64
});
let output = template.render(&globals).unwrap();
assert_eq!(output, "Liquid! 2".to_string());
You can find a reference on Liquid syntax here.
By default, liquid-rust
has no filters, tags, or blocks. You can enable the
default set or pick and choose which to add to suite your application.
Creating your own filters is very easy. Filters are simply functions or
closures that take an input Value
and a Vec<Value>
of optional arguments
and return a Value
to be rendered or consumed by chained filters.
See
filters/
for what a filter implementation looks like. You can then register it by
calling liquid::ParserBuilder::filter
.
Tags are made up of two parts, the initialization and the rendering.
Initialization happens when the parser hits a Liquid tag that has your
designated name. You will have to specify a function or closure that will
then return a Renderable
object to do the rendering.
See
include_tag.rs
for what a tag implementation looks like. You can then register it by calling liquid::ParserBuilder::tag
.
Blocks work very similar to Tags. The only difference is that blocks contain other
markup, which is why block initialization functions take another argument, a list
of Element
s that are inside the specified block.
See
comment_block.rs
for what a block implementation looks like. You can then register it by
calling liquid::ParserBuilder::block
.