[cms] Random new template detection order in theme
By default each template file (*.tpl) discovered during theme scan has url matching it's location on disk:
URL | Template |
---|---|
/theme_name/some_folder/some_template_name.html | /themes/theme_name/some_folder/some_template_name.tpl |
If there is a need to change url, that would lead to that template, then special block comment needs to be added in the beginning of the template:
<!--## <NAME>Template Name</NAME> <DESC>Template Description</DESC> <SECTION>1st Level Section||2nd Level Section||3rd Level Section</SECTION> ##-->
This way template url and it's location in "Structure & Data" is completely controlled using comment block described above.
Index Page Approach
If "index.tpl
" template is present in any directory in theme, then it's content will be displayed automatically. Here is example:
URL | Template |
---|---|
/theme_name/some_folder.html | /theme_name/some_folder.tpl OR /theme_name/some_folder/index.tpl |
/theme_name/some_folder/index.html | /theme_name/some_folder/index.tpl |
Template Scan Problem
File system can't guarantee, that new filenames found in theme during it's scanning are always sorted in same way. That's why it's near to impossible to ensure, that "template_a.tpl" corresponding section would already be present by the time it will be found by theme scanner.
I have several ideas about ways to fix a problem. Please tell me what you think:
- define order for each file/folder in theme that would be used to sort files/folders during scan process
- define priority only for files/folders, that are required to be scanned first comparing to other files/folders in same folder
Order/priority definition can be made in:
- same block comment, that each template file has
- separate file, created per-folder (like .smsignore)
- single per-theme file in theme root folder
- single per-theme file in theme /install/ sub-folder (we already have theme.xml file there)
Solution
- change the "
c:
OnAfterRebuildThemes
" event to unserialize values of "$files
" array (all at once) before using them later - 0.3h - create the "
CategoriesEventHandler::sortByDependencies(array $files)
" method, that will: - 0.5h- accept $files associative array, that is built in "
c:OnAfterRebuildThemes
" event, where:- key is relative path to a template in theme
- value is array, that was parsed from template meta comment
- for each array entry (the template file) build a sorting key like this:
- take array from "section" key of template info (if missing use empty array)
- append value of "name" key to that array (if missing use
'_Auto: ' . $template
) - combine using a separator (e.g. "||")
- sort array using sort key built above (will ensure, that parent templates will be listed prior to child templates)
- return sorted "$files" array
- accept $files associative array, that is built in "
- in the "
c:
OnAfterRebuildThemes
" event call the "CategoriesEventHandler::sortByDependencies
" method on the "$files
" array prior to creating categories from it - 0.2h
Quote: 1h*1.4=1.5h