How to change path to module templates

+
0
-

Currently, my BlogModule is looking for templates in the path:
app/BlogModule/templates/Blog/default.latte

I would like this path to be:
app/BlogModule/templates/default.latte.

I assume this needs to be change/overwritten in the config.neon file.
What needs to be in the config.neon file to change the template dir path?

Thanks
Kevin

+
0
-

A little more poking about, and I found function formatLayoutTemplateFiles()
So, I tried to overide the parent, and the function is called, however, does not change the layout template in any way.

public function formatLayoutTemplateFiles()
{
        $layoutDir = ['app/layouts/@common.latte'];
        return $layoutDir;
}
+
0
-

So.. to override I basically had to copy the formatLayoutTemplateFiles() method from the parent.

/**
 * Formats layout template file names.
 * @return array
 */
public function formatLayoutTemplateFiles()
{
        list($module, $presenter) = Helpers::splitName($this->getName());
        $layout = $this->layout ? $this->layout : 'layout';
        $dir = dirname($this->getReflection()->getFileName());
        $dir = is_dir("$dir/templates") ? $dir : dirname($dir);
        $list = [
                "$dir/../layouts/@common.latte",
        ];
        do {
                $list[] = "$dir/templates/@$layout.latte";
                $dir = dirname($dir);
        } while ($dir && $module && (list($module) = Helpers::splitName($module)));
        return $list;
}

Surely there is an easier way to change the layout template location.

Thanks,
Kevin

Ondřej Kubíček
Member | 494
+
+1
-

you can set layout just calling $this->setLayout($path)

+
0
-

Awesome, thanks.

Solution for anybody following is this:
Sets the layouts to app/layouts/common.latte

<?php

namespace App\BlogModule\Presenters;

// alias Nette for use when extending
use Nette;
use Nette\Application\Helpers;


class BlogPresenter extends Nette\Application\UI\Presenter
{
        /** @var Nette\Database\Context */
        private $database;

        public function __construct(Nette\Database\Context $database)
        {
                $this->database = $database;
                $path = __DIR__.'/../../layouts/@common.latte';
                $this->setLayout( $path );
        }
}