Does the `@` in `@layout.latte` have any significance?
- tom_streeter
- Member | 3
I'm self-taught when it comes to PHP and my instructor has some serious holes in his knowledge. This may be one of them. I used PHP years ago and have only recently come back and it's … different. I like it, and for the most part my knowledge is so outdated that I have the luxury of essentially learning something new without unlearning bad habits. I like that Nette has good practices as a central design principle.
That being said, weird things catch my attention and the default latte
template being called @layout.latte
is just that.
Is there any significance to the @
?
Is it:
- Just an attention-getting device for a human reading the code?
- An informal or formal programming convention I, as someone who occasionally is given money in exchange for writing code, really ought to be aware of? (I hasten to add conventions are generally a pretty good thing, and I'm all in favor of them.)
- Something so mind-bogglingly essential that not knowing it means I should probably abandon all hope of ever being any good at this and, instead, try something I'm equally unlikely to be any good at like, say, interpretive dance?
I think that covers the range of possibilities.
If this is the strangest question you've been asked today, you're welcome.
Last edited by tom_streeter (2021-11-17 19:20)
- Rick Strafy
- Nette Blogger | 81
I think the intention behind this was that folders/files starting with @ will be at the top, I'm also using it in some nette examples but as a directory name, layout file is without the @ at the start, check out https://github.com/…Module/Front and also in @Templates there is @Layout, so I have is as the first folder in directory list.
- tom_streeter
- Member | 3
Rick Strafy wrote:
I think the intention behind this was that folders/files starting with @ will be at the top, I'm also using it in some nette examples but as a directory name, layout file is without the @ at the start, check out https://github.com/…Module/Front and also in @Templates there is @Layout, so I have is as the first folder in directory list.
Thanks! So it's a combination of #1 & #2. Clever.
Another day of avoiding interpretive dance!
(Thanks again)
- Milo
- Nette Core | 1283
The presenter action method may not be defined, existence of template file, e.g. default.latte, is enough.
The @ sign prevents template to be mistakenly used as an action template, because the action name cannot contain such character.
So, it's a little bit security feature.
- tom_streeter
- Member | 3
Milo wrote:
The presenter action method may not be defined, existence of template file, e.g. default.latte, is enough.
The @ sign prevents template to be mistakenly used as an action template, because the action name cannot contain such character.
So, it's a little bit security feature.
I'm glad I asked. This is useful information. I always make note of things that keep me from doing something stupid because doing stupid things is my superpower.
- Rick Strafy
- Nette Blogger | 81
I checked the nette/web-project and I don't see how that might be a security issue, presenter actions are in folders with presenter names and layout is out of that folder, it was like that since initial commit 7 years ago.
Last edited by Rick Strafy (2021-11-17 21:38)
- Milo
- Nette Core | 1283
Sure, but it is not only about @layout.latte
.
One can overload a presenter's formatTemplateFiles()
and change
the action template lookup paths.
Or you can create included templates like @blocks.latte
or
@menu.latte
in the same directory as action templates.
Sure it depends on URL router configuration too.
But the main idea remains – action name must not contain @ char, so template file prefixed by @ cannot be used as an action template.
It is not so critical security topic but better safe than sorry.
- Rick Strafy
- Nette Blogger | 81
Thanks, but I was scared that it may be an issue with current nette web skeleton on github, because I saw project in the past that had it like this, template folder and <presenter>-<action>.latte, but that was probably with the overloaded method as you mentioned.
Last edited by Rick Strafy (2021-11-18 03:57)