It should be possible - by default or with a single config option that is set once - that files in the template folder are automatically added and recognized as available templates and made useable in the web interface, instead of having to add each single one to the settings.py
I like that idea. +1
It would even be better to make that template directory dependent from the configured siteId, so that depending from the site, different templates are selectable.
taking site id into account is on one part interesting, but then again only for those who have multiple sites in one install. I don't know how many these are - I am not one of them for now. So to not make the system more complex for simple use cases, that should also be configurable with a simple default :)
how can we "detect" what a cms template is and not something else?
by not allowing to put anything but templates in the directory?
I see there might be some corner cases, like templates that shouldn't be directly used, but only be there for extension, and in compley environments with many editory, you don't want them to be visible.
In that case you have to continue and do configuration as it is.
But it's good to have one simple way that makes it easy to add and use templates without fiddling with configs for smaller usages.
Simple default - configurable complexity :)
Something like having:
CMS_TEMPLATE_DIR = "cms/pages/"
Which causes the CMS to pick up any file in that specified subdirectory of the TEMPLATE_DIRS as a potential page template to use.
The description used could be a simple filename->label conversion, such as is done by default with Django Model field names.
CMS_TEMPLATE_DIR = "cms/pages/"
how would translation of template names be handled?
I was thinking about allowing regular expressions for template names, but Patrick is right. Another idea would be to set the template name in the template itself, using a special template tag.
Translation of template cases should not be necessary in first place, as I see it.
If the files are nicely named, that should do for the simple cases. Just strip the .html and all is fine.
The need to have names for a template in the UI that differ from the filename is also something that can, if needed be handled by explicit configuration.
The idea toi set the name(also in addition to the filename that should be good) in the template itself also sounds nice.
If You have more templates, You probably have some base template(s), which you extend in the other templates. Such base templates are usually not supposed to be available for rendering pages.
Also You probably have 404.html and 500.html in Your templates dir.
Therefore I don't believe there would be many use cases for taking all the templates.
You may try to detect cms templates by placeholders but it wouldn't be reliable anyway.
But. You may easily solve it by creating a sub-directory dedicated for CMS templates.
It would be clean, there would be no collisions, no exceptions, no corner cases.
The name of such sub-directory could be set by CMS_TEMPLATES_DIR.
Consider this settings, which You may use right now:
CMS_TEMPLATES_DIR = os.path.join(TEMPLATE_DIRS, 'cmspages')
CMS_TEMPLATES_PREFIX = 'cmspages/'
CMS_TEMPLATES = tuple((CMS_TEMPLATES_PREFIX + tpl, tpl) for tpl in os.listdir(CMS_TEMPLATES_DIR))
@misli gotta go and test this, sounds like it's just what I mean :)
Maybe even easier, for very simple cases I'd not add a subdirectory.
@digi604 I hope you understand my idea - I am proposing to have a system that is as simple as possible for the simple cases, and can be configured as desired for complex cases :)
i like it.... simple by default and the ability to configure it further if you need to do so.
it would already suffice if you'd declare a prefix like cmstemplate_fullwidth.html or tpl_fullwidth.htmt
@misli , nice approach to this problem, but how to you handle the name of the template to be shown in the select box where you choose the template.
@digi604 , does it really make sense to separate the naming of the template (in settings.py) from the template code itself? What I mean, if the same CMS template is used from two different CMS instances, does it really make sense to name them differently in each project? Shouldn't the name of a template be part of itself to keep that information contained in itself?
@jrief as of the question if it makes sense to separate the filename and Name in the Editor/Admin GUI: for myself using Aldryn in a simple case, I don't need it, I even don't want to have to think about any name different from the actual filename and not have to write more configuration than necessary - and dropping a file in the templates folder is a clear enough intention to use it as template :)
In many other complex cases - complex organisations, different customers with different editor people, it might make very much sense to have - the possibility to have different names. Just think - one wants to have it called "Start" page, the other "Home" - for many reasons - one might also be translation of the name.
I'm a bit busy the next week but hope to come to check some of the ideas we discussed here and see if I come up with a solution.
I just wanted to show that it already is simple and it already gives You powerful configuration since You use python in the settings.
template directory has been added