CMS_SECURITY_POLICY_V1 in OctoberCMS 4?

I’m just working on the update to OctoberCMS 4 and I am facing the problem, that lots of things does not work:

  • Variables are null in twig
  • default partials are not found on Redirect::back()

If I remember right, all this could be solved with CMS_SECURITY_POLICY_V1 = true, which is still set. But does it also have impact or was it removed internally?

I’m not sure its related to the policy because it throws an error, instead of making things null. Try setting this to make missing variables (and components) also throw an error so you can track down what is happening.

CMS_STRICT_VARIABLES=true
CMS_STRICT_COMPONENTS=true

Ok I tried to dig deeper in the problem, and could resolve both issues. Here’re rough hints for people with the same problem:

The partial ‘default’ is not found.

For some reason I had this code in one of my components:

data-request-update="{ default: true }"

I guess the code was simply ignored in OctoberCMS 3 and is now throwing errors.

However, there’re multiple ways to refresh some website areas, so this should be an easy fix

Variables are null in twig

All links to other pages used in components are defined as xxxPage on the page as component variable. Therefor, they’re also available as

{% set itemPage = __SELF__.itemPage %}

In OctoberCMS 3. But what I found, this is not correct within OctoberCMS 3 already.

Since I have to define a lot of pages, I created a PagesTrait which checks, if every page, required for the component, is indeed defined or if one is missing. This PagesTrait adds the value from the page as dynamic property via addDynamicProperty. Then you can call the page in the component partials like this:

$this->property("itemPage")

The call with property() is the intended way if I read it right, and the fact it worked before was never intended and is now not possible anymore due to twig not calling dynamic variables.

Maybe this helps somebody out there.

You might correct me if I’m wrong ofc :wink:

1 Like