Skip to content

Instantly share code, notes, and snippets.

@leoh
Forked from sevennineteen/example.json
Last active April 8, 2022 09:43
Show Gist options
  • Save leoh/9754461 to your computer and use it in GitHub Desktop.
Save leoh/9754461 to your computer and use it in GitHub Desktop.
{ "path": "/content/geometrixx/my-first-jinja-page",
"properties": [
{ "name": "jcr:primaryType",
"value": "cq:Page" }],
"nodes": [
{ "path": "jcr:content",
"properties": [
{ "name": "jcr:primaryType",
"value": "cq:PageContent"},
{ "name": "sling:resourceType",
"value": "geometrixx/components/widepage"},
{ "name": "jcr:title",
"value": "{{ page.title }}" },
{ "name": "cq:template",
"value": "/apps/geometrixx/templates/widepage"},
{ "name": "cq:tags",
"type": "String[]",
"value": {{ page.tags|jsonify }} },
{ "name": "jcr:description",
"value": "{{ page.description }}" },
{ "name": "sling:vanityPath",
"value": "/connector-examples/json/" }]}
]
}
import json
from jinja2 import Environment, FileSystemLoader
env = Environment(loader=FileSystemLoader('.'))
env.filters['jsonify'] = json.dumps
template = env.get_template('example.json') # Template file at ./example.json
page = {
'title': 'Jinja Example Page',
'tags': ['jinja', 'python', 'migration'],
'description': 'This is an example page created using Jinja2 with a JSON template.'
}
print template.render(page=page)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment