I think I am missing something in how to implement the Import plugin (https://github.com/Perlkonig/grav-plugin-import )
I have added a file named ex_config.json to the folder for a page.
For the docs.md file in that folder I have added imports: ex_config.json
to the frontmatter and then used {{ page.header.imports.ex_config.json }}
in the main body of the markdown.
This is not working and the page only renders {{ page.header.imports.ex_config.json }}
kosnik
September 23, 2017, 1:49am
2
Hello,
I don’t understands your purpose.
For example in your page header :
import:
- 'user://data/imports/test.yaml'
and in file grav-root/user/data/imports/test.yaml
-
name: toto
keywhatelse: 1529
-
name: jack
keywhatelse: 7589
And use in template or in the Markdown body (if enable twig processing in configuration system) :
{{ page.header.imports|json_encode(constant('JSON_PRETTY_PRINT')) }}
the result output :
{"test":[ {"name":"toto","keywhatelse":"1529"},{"name":"jack","keywhatelse":"7589"}]}
and use in template (*.html.twig) or in the Markdown body (if enable twig processing in configuration system) :
{% for list in page.header.imports.test %}
<div>
Name : {{ list.name }}</br>
key what else : {{ list.keywhatelse }}</br>
</div>
{% endfor %}
the result of the html output :
<div>
Name : toto</br>
key what else : 1529</br>
</div>
<div>
Name : jack</br>
key what else : 7589</br>
</div>
And if you want use specific couple key/value, you use :
{{ page.header.imports.test[1].keywhatelse }}
The output result is :
7589
I hope it will help you
What does <pre>{{ page.header.imports|json_encode(constant('JSON_PRETTY_PRINT')) }}</pre>
output?
Have you enabled twig processing for the page? Since you put the code in the Markdown body, this has to be enabled for the page.
Thanks @chris_jung and @kosnik I have it working now. You’ve been very helpful
1 Like