including *.latte templates without caring the directory structure
- medhi
- Generous Backer | 236
This is ugly:
{include '../../../menu.latte'}
{* or *}
{embed '../../../menu.latte'}{/embed}
It's so annoying to search how deep in my directory structure I am, and it
should not matter, why should I care?
Also, if the parent template is moved upper or lower, these paths stop
working.
How about to put all these templates – that are used only to be included – to some predefined directory and then include them without caring about the directory structure?
Last edited by medhi (2020-11-06 22:52)
- Rick Strafy
- Nette Blogger | 6
So you want all templates that you include somewhere in one directory? It's sounds like very bad joke, projects with folders like Includes or Utils are considered as those with design flaws where author didn't make effort to make better project structure, but it's not always true, usually it's better use something like Article/@Common to have common templates that have to do something with articles.
But on the other hand, it would be cool to define template root, for instance
my template root would be here https://github.com/…%40Templates
so I could use {embed '/@Layout/Embeds/menu.latte'}
anywhere, but
until now I didn't have problem with paths, it's very rare when I move latte
file to other directory.
Last edited by Rick Strafy (2020-11-06 23:13)
- medhi
- Generous Backer | 236
I was not proposing any particular solution, but just a general idea to have more pleasant way to include a template.
Now I have something like this in my code:
{embed '../../../../templates/infobox.latte'}
...
{/embed}
Which is… difficult to read at least?
Absolute paths? Maybe, why not :)
- David Grudl
- Nette Core | 7412
You can set your own root for the Latte and then all “absolute” paths will be relative to this root:
$this->template->getLatte()->setLoader(
new Latte\Loaders\FileLoader(__DIR__ . '/templates')
);
The problem is that Presenter is not ready for this and use absolute paths in
methods like formatTemplateFiles(). The easiest solution is therefore to use a
variable $root
or as he wrote @filsedla define constant.
- medhi
- Generous Backer | 236
Šaman wrote:
medhi wrote:
You won't pass a big chunk of HTML/latte into a Control.
Why? Control has own independent template. Even Presenter is Control.
Because I need to pass different big chunks of HTML. A modal for example. It has its own template, but always has different body, which is not suitable for control to pass in.