繁体   English   中英

Twig模板未接收变量

[英]Twig template not receiving variables

我有一个CMS页面,其中包含一个名为pageTitle的组件,该组件将显示格式化的页面标题。 我正在尝试将变量传递给该组件,但似乎没有收到它。 我的页面中有以下内容:

title = "Test"

[pageTitle]
title="Test"
==
{% component 'pageTitle' title="Test" %}

(我认为)应该使用3种不同的方式将变量传递给该组件,并且在我拥有的components/pagetitle/default.htm中(以及其他HTML):

{{ title }}

HTML可以很好地呈现,但是不输出变量。

我还尝试将以下内容放入我的components/pagetitle/PageTitle.php主类文件中:

public function defineProperties()
{
    return [
        'title'    => [
            'title'       => 'Title',
            'description' => 'The page title',
            'type'        => 'string',
        ],
    ];
}

但是,这也没有效果。

如果我添加标头部分,可能还需要注意在我的components/pagetitle/default.htm ,例如:

title = "Test"
==
HTML content here

整个内容显示在输出HTML中,包括标题。 所以我想知道它是否被Twig解释器以外的其他东西解释。

嗯,我很确定没有什么可拦截的。

你能尝试这个吗,因为它在我本地工作

<div id="tile-area">
    <h1>default one {{ __SELF__.property('title') }}</h1>
</div>

它应该工作。

您还可以从这里获取更多参考: https : //octobercms.com/docs/plugin/components#component-properties

如有疑问请发表评论

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM