T.O.M.
T.O.M.

Reputation: 93

Custom page variable in OctoberCMS

Is it possible to use custom page variable in Configuration section in OctoberCMS? When I do this:

url = "/blog"
layout = "default"

custom_var = "value"
==
{{ custom_var }}

my custom_var is deleting when edit page from admin panel.

Upvotes: 1

Views: 1449

Answers (3)

Tauhed
Tauhed

Reputation: 109

Yes, its possible to set custom variable into page. you can try the following code into the php section

function onEnd() {
    $this->page->custom_var = 'some data';
}

And then you can use this custom_var into your layout file like

{{ this.page.custom_var }}

Upvotes: 2

shakogele
shakogele

Reputation: 399

If you want to define new variables inside markup you can use following syntax:

{% set custom_var = 'some data' %}

Upvotes: 0

Hardik Satasiya
Hardik Satasiya

Reputation: 9693

It seems this was the old way of defining all stuff in single view (visual representation)

now its divided in 3 portion

1st name and url(slug) then 2nd markup(html) section

enter image description here

3rd code section

enter image description here

so you can follow new way of declaring things and it should work

use code section add this

public function onStart() {
    $this['custom_var'] = 'some value';
}

use markup section and add this

<h1>{{ custom_var }}</h1>

it will work, still any issue please comment.

Upvotes: 2

Related Questions