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

bezgodov
bezgodov

When i try to include file with twig extension i get An exception has been thrown during the rendering of a template ("The specified file extension [twig] is invalid.").

If i change October\Rain\Halcyon\Model property $allowedExtensions to ['twig', 'htm'] then everything works fine, but after composer install own lines, of course, will be removed.

My question: how may i extend this property to use twig? I tried something like this in my Plugin.php

Event::listen('cms.page.init', function(Cms\Classes\Controller $controller) {
    $page = $controller->getPage();
    $page['allowedExtensions'] = ['htm', 'twig'];
})

Last updated

mjauvin
mjauvin
October\Rain\Halcyon\Model::extend(function ($model) {
   $model->allowedExtensions[] = 'twig';
}) ;
bezgodov
bezgodov

Your code gives Indirect modification of overloaded property Cms\Classes\Page::$allowedExtensions has no effect

If i change it to

$model->allowedExtensions = ['htm', 'twig'];

it gives Class name is not registered for the component 'allowedExtensions'. Check the component plugin.

Cause class contains magic __set then i use

$model['allowedExtensions'] = array_merge($model->getAllowedExtensions(), ['twig']);

And everything works fine. Thank you!

1-3 of 3

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