Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Plugins

Correct usage of Import plugin

Started by Mike 9 years ago · 3 replies · 1414 views
9 years ago

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 }}

9 years ago

Hello,
I don't understands your purpose.
For example in your page header :

YAML
    import:
        - 'user://data/imports/test.yaml'

and in file grav-root/user/data/imports/test.yaml

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) :

MARKDOWN
    {{ page.header.imports|json_encode(constant('JSON_PRETTY_PRINT')) }}

the result output :

JSON
    {"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) :

TXT
{% 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 :

HTML
<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 :

TXT
{{ page.header.imports.test[1].keywhatelse }}

The output result is :

TXT
7589

I hope it will help you

last edited 09/26/17 by kosnik
9 years ago

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.

9 years ago

Thanks @chris_jung and @kosnik I have it working now. You've been very helpful

👍 1

Suggested topics

Topic Participants Replies Views Activity
Plugins · by Rene, 1 week ago
2 42 1 week ago
Plugins · by Xavier, 4 weeks ago
2 53 4 weeks ago
Plugins · by Luka Prinčič, 7 years ago
3 1179 1 month ago
Plugins · by Sebastian van de Meer, 1 month ago
1 47 1 month ago
Plugins · by PIERROT Alain, 2 months ago
3 71 2 months ago