简体   繁体   中英

Twig template not receiving variables

I have a CMS page that includes a component called pageTitle that will display a formatted page title. I am trying to pass a variable to that component, but it does not seem to be receiving it. I have the following in my page:

title = "Test"

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

which (I think) should be using 3 different ways to pass a variable to that component, and in components/pagetitle/default.htm I have (among other HTML):

{{ title }}

The HTML renders fine, but the variable is not being outputted.

I have also tried putting the following in my components/pagetitle/PageTitle.php main class file:

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

However that also has no effect.

It is probably also worth noting that in my components/pagetitle/default.htm if I add a header section, like:

title = "Test"
==
HTML content here

the whole thing is displayed in the output HTML, including the header. So I'm wondering if it is being interpreted by something other than the Twig interpreter.

hmm, i am pretty sure there is nothing to intercept.

can you try this one as its working on my local

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

it should work.

further more you can take reference from here : https://octobercms.com/docs/plugin/components#component-properties

if any doubt please comment

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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