Jinja use custom block markers

From UVOO Tech Wiki
Revision as of 23:08, 6 March 2024 by Busk (talk | contribs) (Created page with "``` from jinja2 import Environment, FileSystemLoader # Create a Jinja environment with custom variable markers custom_env = Environment(loader=FileSystemLoader('your_template...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
from jinja2 import Environment, FileSystemLoader

# Create a Jinja environment with custom variable markers
custom_env = Environment(loader=FileSystemLoader('your_template_directory'),
                         block_start_string='[%',  # Change this to your desired start marker
                         block_end_string='%]')    # Change this to your desired end marker

# Load your template
template = custom_env.get_template('your_template_file.html')

# Render the template with your data
rendered_output = template.render(your_variable='some_value')

# Print or use the rendered output as needed
print(rendered_output)