Grav - Using shortcodes in twig

大憨熊 提交于 2019-12-24 23:15:54

问题


Following this question, I have found that there is a plugin named shortcodes which might be helpful here.

I have installed the plugin and created a new page:

---
title: slide1
media_order: slider1.jpeg
taxonomy:
    category:
        - 'Home Slider'
process:
    markdown: true
    twig: true
routable: false
cache_enable: false
visible: false
---

[section name="slide_title"]
Precisión y Calidad
[/section]

[section name="slide_subtitle"]
La máxima calidad y seguridad para nuestros clientes
[/section]

[section name="slide_link"]
www.google.es
[/section]

Then I have an invoked partial which makes:

{% for slide in taxonomy.findTaxonomy({'category': 'Home Slider'}) %}
    <span>TEST</span>
    <span>{{ slide.title }}</span>
    <span>{{ slide.shortcode.section.slide_title }}</span>
    <span>{{ slide.shortcode.section.slide_subtitle }}</span>
    <span>{{ slide.shortcode.section.slide_link }}</span>
{% endfor %}

But this generates just:

TEST
slide1 

And it does not output the shortcode section contents.


回答1:


The documentation you linked to shows the correct syntax when you are not dealing directly with the page variable:

{{ slide.contentMeta.shortcodeMeta.shortcode.section.slide_title }}
{{ slide.contentMeta.shortcodeMeta.shortcode.section.slide_subtitle }}
{{ slide.contentMeta.shortcodeMeta.shortcode.section.slide_link }}


来源:https://stackoverflow.com/questions/48912840/grav-using-shortcodes-in-twig

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!