This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

Username123
Username123

I'm confused about the process, but I'll try to explain.

The problem with the filter.

{% for page in pages if Something_1 == Something_2 %} .... {% endfor %}

The filter works if directly specify Value for Something_2:

function prepareVars() { $this['something_2'] = 'Value'; }

But it is necessary that the "Value" was taken from Сustom Field staticPages. Like

{variable name='Value' type='text' label='label' tab='tab'}{/variable}

How to do it?

If just specify so (without prepareVars), the filter does not work:

{Variable Name = 'Something_2' Type = 'Text' Label = 'Label' Tab = 'Tab'} {/ Variable}

It is necessary to somehow add it to prepareVars.

Last updated

daftspunky
daftspunky

You could try to access the staticPage component to obtain the extra data.

$var = $this->staticPage->extraData['Something_2'] ?? null;

It depends on where in the application lifecycle this is called to know if the data will be available.

Username123
Username123

I am trying to check it like this:

function onStart() {

    $var = $this->staticPage->extraData['Something_2'] ?? null;

    $this['Test'] = $var;   

}
{variable name='something_2' type='text' label='label' tab='tab'}{/variable}
{{ something_2 }} - data

{{ Test }} - nothing.

What am I doing wrong?

daftspunky
daftspunky

This should work...

function onStart() {

    $var = $this['something_2'];

    $this['Test'] = $var;   

}
Username123
Username123

Doesn't work for me

My layout:

description = ""

[staticPage]
useContent = 1
default = 1

==
<?php
    function onStart() {
        $var = $this['something_2'];
        $this['test'] = $var;           
    }
?>
==
{variable name="something_2" type="text" label="label" tab="tab"}{/variable}

<!doctype html>
<html>
<body>
{{ something_2 }} - data
{{ test }} - nothing
</body>
</html>
daftspunky
daftspunky

It does look like a lifecycle issue, try using onEnd instead of onStart

Username123
Username123

Works if "onEnd" or "onBeforePageStart", but that doesn't solve my problem.

But I'm getting closer to solving the problem :)

Variable disappear after using "form_ajax".

{variable name='something_2' type='text' label='label' tab='tab'}{/variable} 
{{ form_ajax('onFilter', { update: { 'List': '#List' } }) }}
...
{{ form_close() }}

List.htm

description = "List"
[viewBag]
==
{{ something_2 }} 

If apply Filter, {{ something_2 }} disappears. Does not disappear if specified as {{ this.page.something_2 }}.

BUT, THIS.PAGE.something_2 is not supported by default, need to add something_2 to "$viewBagToSettings" Rainlab\pages\classes\Controller.php.

I don't want to add this after every update staticPage, maybe there are other options?

Username123
Username123

Found the answer here https://stackoverflow.com/questions/48199529/octobercms-variable-disappears-after-ajax-request/48200882

Just added

function onFilter() {
    $this->controller->pageCycle();
} 

Last updated

daftspunky
daftspunky

Aha, didn't realise it was inside an AJAX handler.

function onFilter() {
    $this->pageCycle();
} 

That will do the trick! Nice

1-9 of 9

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.