Closed tristanlins closed 12 years ago
It's interesting, I was just going to make a feature request about templates in Contao.
I agree with tristanlins that we need to have one basic template (for example *.html
). And this template should be edited in HTML5 format by deafult (in the future it will be HTML6, HTML7...). So, what about XHTML? The answer is almost exists in Contao. For getting XHTML we can use toXhtml method from String
class. So, if we wanted to use XHTML code we can just convert modules templates *.html
to XHTML format (and caching it somewhere). In this case we will have only one template *.html
instead of currently used *.html5
, *.xhtml
and *.tpl
...
p.s. sorry for my bad english... :) I hope you understand what I mean.
Why not resurrect .tpl
? So, only load .html5
if HTML5 is enabled and the file is available, otherwise fall back to .tpl
? Thus, .xhtml is no longer needed, of course.
I'm happy with _.html5 and .xhtml and i'm think is not the right way to get back to .tpl (even if i remove the triggererror from all of my installations). .tpl give no information about the content. .tpl could be everything possible... The basic .xhtml45 template (or .html as @DyaGa recommended) should be in XHTML syntax because XHTML is a subset of HTML (not vise versa). The *toXhtml method is not necessary! And using XHTML syntax in regular HTML is not good or bad. It's just HTML ;-)
My idea was not to convert from one syntax to another! But i do not need the differences between XHTML/HTML5 in all templates. Sometimes i need it and sometimes not.
The detection logic should be:
In my opinion we should make sure, the template engine of Contao can handle whatever format is needed. We "forced" Leo to keep the .xhtml way too which is why we have two template extensions today (.xhtml, .html5). Otherwise Leo would have only provided the HTML5 way :) I know that Leo has invested a lot of time in making this possible but unfortunately, as you can see from tickets like this one, it seems like the template engine is still not what the people are looking for :(
Personally, I feel like we could solve it really, really easy and I took other frameworks as reference to see how they work.
I think, we should go the "[namespace - required]:[template name - required].[format - optional].tpl" way:
This would give us an enormous flexibility. Let me explain:
This is the way I'd go. Provides a lot of advantages to the system we know today, includes (hopefully) all the requirements you mentioned here (like the fallback) and should be possible to implement :)
I'm realy unhappy with using .tpl for all templates! My editor support indeep syntax highlighting, so i would have less "editing" problems, but I think its not the right way. I don't know your editor, but if you add .tpl for HTML format, what do the editor, if you have a non-HTML Template like JSON? Most IDE's support JavaScript/JSON, but you will not get the editor support, if all templates, including the JSON templates ending with *.tpl.
The _.xhtml45 templates is just a fallback for .xhtml or .html5, but _not* for _.json for example. Using a basic template .tpl as general fallback is not\ the right way, you supposed the JSON format as example. What if some extension does not provide a JSON template? Should Contao use the fallback .tpl template, that contains HTML and use it in a JSON context? Thats absolutely the wrong way how Contao decide which template should used! In this case a *blank_ fallback template should used, but this is not the topic of this discussion.
I don't want to discuss about non html formats, please open a new ticket for this. @Toflar but your namespace idea sounds good, please explain in detail in a new ticket ;-)
Just to make it clear, I didn't say that we should use *.tpl for all templates.
Why do we need yet another format if we already have a legacy one (*.tpl) that was actually meant for XHTML?
A maybe better way we discuss in the IRC about, is to fallback from .html5 to .xhtml. XHTML is a compatible subset of HTML (including HTML5). A general legacy format is not the right way. .tpl was the old meaning of XHTML but what it will be in Contao >= 2.10? Contao 2.10+ supports other formats like .json. If we have a general legacy format .tpl that will be used as general fallback (the current behavior), this may result in an HTML/JSON mix, if an extension or Contao itself does not support the .json format.
Of course .tpl should not be used as a general fallback. Only for .html5.
But well, it was just an idea, maybe not the smartest one ;-).
All I can offer you is to remove the warning message when using .tpl files. However, I don't think a fallback type is a good idea.
Personaly i would prefer to remove the .tpl fallback, removing the error message in the core will be end in reusing the .tpl files. If this is what you want, than do so, but i don't think you want this. Currently we have a fallback (.tpl) and if you remove the error message, you accept this fallback, but on the other side you say "I don't think a fallback type is a good idea."?! ;-) What about removing the .tpl fallback (in 2.11 or 2.12) and just make a fallback from .html5 to .xhtml? Then we have no separate fallback type, because XHTML is (nearly full) compatible to used in HTML5 documents. And you can provide separate .html5 files, if you need special HTML5 features/elements.
I would prefer to have one template ending, that can be used for xhtml AND html5 automatically. Currently i work on an extension, that does not (need) to use the html5 element in some templates. But this templates are extremely big and if i change one template, i have to totaly change 3 big files (.xhtml, .html5, .tpl). Can't we add another template ending that is used as fallback (not the error triggering .tpl) for .xhtml or .html5? I know there is an XHTML5 Standard, maybe we should use another extension for this (like *.xhtml45).
In my case i have this template structure: mod_X.html5 -> uses HTML5 elements mod_X.xhtml/mod_x.tpl -> uses XHTML4 elements
for details inside of the template i have a backend selectable template: details_X.html5/details_X.xhtml/details_X.tpl -> all templates are absolutely equal because there is no need for special HTML5 elements (i allready use the HTML5 elements in the mod_X.html5 templates).
This would simplify the template handling in most extensions. If this feature may be accepted, i would make a pull request, but first i want do discuss about it.