Grav-在树枝中使用简码 [英] Grav - Using shortcodes in twig

查看:86
本文介绍了Grav-在树枝中使用简码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题之后,我发现是名为短代码的插件在这里有帮助.

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

但这会生成:

TEST
slide1 

它不输出简码部分的内容.

And it does not output the shortcode section contents.

推荐答案

当您不直接处理page变量时,链接到的文档将显示正确的语法:

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

这篇关于Grav-在树枝中使用简码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆