Skip to content

bhftbootcamp/Jinja2Cpp.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Jinja2Cpp.jl

Stable Dev Build Status Coverage Registry

Julia wrapper for Jinja2Cpp for Jinja2 template rendering.

Installation

If you haven't installed our local registry yet, do that first:

] registry add https://github.com/bhftbootcamp/Green.git

To install Jinja2Cpp, simply use the Julia package manager:

] add Jinja2Cpp

Usage

This example shows the basic tools for rendering a Jinja2 template depending on the passed values.

using Jinja2Cpp

source = """
{% set greetings = {
    "en" = {"text"="Hello",   "flag"="🇬🇧"},
    "es" = {"text"="¡Hola",   "flag"="🇪🇸"},
    "fr" = {"text"="Bonjour", "flag"="🇫🇷"},
    "de" = {"text"="Hallo",   "flag"="🇩🇪"},
    "ru" = {"text"="Привет",  "flag"="🇷🇺"},
    "zh" = {"text"="你好",     "flag"="🇨🇳"}
} %}

{%- if user_lang in greetings | list -%}
{{- greetings[user_lang].flag }} {{ greetings[user_lang].text -}}
{% else -%}
🌍 Hello, world!
{%- endif -%}
"""

tmpl = Jinja2Template(source)

julia> jinja2_render(tmpl, Dict("user_lang" => "es"))
"🇪🇸 ¡Hola"

julia> jinja2_render(tmpl, Dict("user_lang" => "zh"))
"🇨🇳 你好"

julia> jinja2_render(tmpl)
"🌍 Hello, world!"

Useful Links

Contributing

Contributions to Jinja2Cpp are welcome! If you encounter a bug, have a feature request, or would like to contribute code, please open an issue or a pull request on GitHub.

About

Julia wrapper for Jinja2Cpp for Jinja2 template rendering

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •