We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Default title, assets defined in layout or better in a event?[solved]

Hi, I created my base layout and defined there in the head my default assets.

<?php
/* @var $this \Phalcon\Mvc\View\Engine\Php */
$this->tag->setDoctype(\Phalcon\Tag::HTML5);
$this->tag->setTitle("Default Title");
$this->assets->addCss('css/bootstrap.min.css')
             ->addCss('css/style.css');
$this->assets->addJs('js/jquery.js')
            ->addJs('js/bootstrap.min.js');
?>
<?=$this->tag->getDoctype();?>
<html>....

Is this the usual way or should I define the default assets and my default title in a view event like beforeRenderView? Somehow I have the feeling that it is better to define the base title/assets in an event because view's shouldn't have any logic.



1.9k
Accepted
answer

Okay I think I got it. I moved the data to the ControllerBase class initialize function. I think this makes more sense. If someone has a better solution/way to do this please let me know.