Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

better template organization / optimize clarity #8779

Open
tvstaveren opened this issue Aug 30, 2017 · 13 comments
Open

better template organization / optimize clarity #8779

tvstaveren opened this issue Aug 30, 2017 · 13 comments
Labels

Comments

@tvstaveren
Copy link

tvstaveren commented Aug 30, 2017

Currently all templates for a theme are stored in one folder (which can be selected in the theme settings) and can only be organized by a very good system for their file names. I understand that subfolders are for different themes but isn't there a way to optimize the whole approach?

Especially when using complex frameworks (e.g. bootstrap) or extensions (e.g. metamodels) the template folder is a mess, regardless of any file naming system.

It would be great for a lot of projects and people to have a possibility to organize the templates better, f.e. by using subfolders and scanning them recursively for one specific theme, using labels or anything that allows me to do something similiar to this:

/templates
----/myTheme (select this folder in theme settings)
--------/navigation (templates in this folder can be selected in every module)
--------/metamodels (templates in this folder can be selected in every module)
--------/calendar ("-")
--------/newsletter ("-")
----/otherTheme
--------/navigation
--------/metamodels
--------/calendar
--------/newsletter
--------/and so on...

@Aybee
Copy link
Contributor

Aybee commented Aug 30, 2017

Additionally I want to point out, that the filter search for name seems not to work.

@tvstaveren
Copy link
Author

true, tested in 4.4.3

@xchs
Copy link
Contributor

xchs commented Aug 30, 2017

This issue belongs to the contao/core-bundle repository since Contao 3.5 is feature complete.

@tvstaveren
Copy link
Author

Sorry, I'm new to the github workflow. What am I supposed to do? Should I report the issue / feature request there?

@xchs
Copy link
Contributor

xchs commented Aug 30, 2017

Don't worry about it. I think Leo (or the issue-bot) will move the ticket accordingly.

@tvstaveren
Copy link
Author

Ok please also move the feature request regarding the template organisation and not only the issue with the filter search if possible, thanks very much :)

@leofeyer
Copy link
Member

leofeyer commented Sep 1, 2017

The reason why we are not supporting nested folders in the custom templates directory is the file_exists() call, which is executed one time for each template:

https://github.com/contao/core/blob/master/system/modules/core/library/Contao/TemplateLoader.php#L103

The same applies to the /templates directory BTW.

@contao/developers I understand the usability problem but I also think that a recursive file search will noticeably affect the performance. What do you think?

@asaage
Copy link

asaage commented Sep 1, 2017

Maybe you can class-inherit the first part of the templatename (like fe_, ce_, mod_, news_ cal_, block_, form_, ... ) and use this as a subfolder 🤔

@Toflar
Copy link
Member

Toflar commented Sep 1, 2017

I think it would be very easy to implement if we added all the templates to the cache as well. Which would btw also make it faster. Here are the two options

  1. we leave it as is.

    • Advantages: A new or renamed template is always loaded live so it's developer friendly during development.
    • Disadvantages: It's slower in production and it doesn't allow a nested structure because that would make it even slower. Also, it's inconsistent because if you place a template in system/modules/whatever/templates or vendor/... you need to clear the cache to make it work, if it's in /templates it's loaded live.
  2. we add the /templates to the template cache as well.

    • Advantages: Works the same as templates in modules/bundles. It's way faster in production. It allows for arbitrary nesting levels.
    • Disadvantages: You have to clear and rebuild the cache every time you rename or add a new template (note: if you change the content, that's no problem! It's just about the paths) or make sure you work in the development mode app_dev.php. We might add a hint in the back end if you're navigating there in production mode.

Needless to say that I fancy version 2. In my opinion everything should be optimized for production.

@asaage
Copy link

asaage commented Sep 1, 2017

If you allow arbitary nesting how would you prevent possible inconsitencies?
like templates/themeA/news_full.html5vs templates/themeA/news/news_full.html5

@Toflar
Copy link
Member

Toflar commented Sep 1, 2017

Same as in all other modules too. The last one wins.

@tvstaveren
Copy link
Author

Since I'm not a real developer I just want to add something to the discussion from the usability point of view... how about a small update for the whole "Templates" area which includes:

  • (if inconsistencies, @asaage ) an info box where current inconsistencies are listed
  • (if inconsistencies @asaage , @Toflar ) something where the user gets an explanation that the most recent template is used, the name of this template and its path and other templates with the same name
  • (@Toflar ) a toggle for activating / deactivating the cache for all the templates and some info for the user what this means for his production / dev work OR just a button to rebuild the cache with some information what this means

and for all templates in the templates list some extra information for each template (in a new column or in brackets behind the template name or whatever):

  • name and ID of the module that is using this template right now and a quick link to this module
  • some space for a short comment to describe the template

Just some thoughts since I'm working with Contao for years now and in my opinion the templates area needs an upgrade. Espacially when using 3rd party modules you have a lot of templates and need a better management and performance.

Short: Implementing @Toflar's ideas inlcuding cache for /templates and last one wins and wrapping them in a small and usable template manager would be a real improvement :)

@leofeyer
Copy link
Member

leofeyer commented Sep 7, 2017

As discussed in Mumble on September 7th, having subfolders is something we want to support. To accomplish this, we have to add the custom templates to the template cache. The cache then needs to be updated (in an atomic operation) if a new file is added or an existing one is renamed or removed.

@leofeyer leofeyer added this to the 4.5.0 milestone Sep 7, 2017
@leofeyer leofeyer removed this from the 4.5.0 milestone Nov 8, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

6 participants