Ad

Twig Template Not Receiving Variables

- 1 answer

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.

Ad

Answer

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

Ad
source: stackoverflow.com
Ad