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 主 class 文件中:

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

然而那也没有效果。

可能还值得注意的是,在我的 components/pagetitle/default.htm 中,如果我添加一个 header 部分,例如:

title = "Test"
==
HTML content here

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

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

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

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

应该可以。

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

如有疑问请评论