1. Dynamic CSS
Yesterday the question popped up whether it is possible to access the ZenMagick API from within a CSS / JavaScript file.
This obviously involves a performance penalty. Nevertheless it is possible.
The first step is to rename the file. This is essential, because otherwise your PHP will never be executed. For example, you’d rename your site.css file to site.css.php. The second step is to include the ZenMagick file external.php.
Example: (This examle assumes that your CSS file is located in the theme’s content folder)
<?php include '../../../external.php'; ?>
After that you can start using the ZenMagick API as you would in any other template file.
2. Organizing template files in subfolder
Currently all views with the exception of email and popup templates are stored in a single folder. With the way URLs are mapped in ZenMagick (ZMUrlMapper) it is easy to change that.
Let’s have a look at how things are done for popups right now (core/settings/url_mapping.php):
$urlMapper->setMapping(null, 'popup_search_help', 'popup_search_help', 'PageView', 'subdir=popup');
The main_page value popu_search_help is mapped to a template (also) named popu_search_help. However, the property subdir is set (on the configured view ZMPageView).This means the view will look for the template file in a subfolder popup. To add to this twist, there is some magic code to trim everyting up to the first ‘_’ in the template name when constructing the final filename. This has historic reasons and is likely to be removed in the future. So, this mapping will resolve to (within the theme folder): content/views/popup/search_help.php.
There is another way of archiving the same that is a bit more sane (and a lot simpler), though:
$urlMapper->setMapping(null, 'popup_search_help', 'popup/search_help');
The template value is considered to be the filename without the set template filename extension. So this second mapping will resolve to the same file as the first, just in a much more elegant way.
Conclusion: To organize your view templates in different folders, all that is requires it to add a relative path to the mapping.
Please note that this would require some more mappings than there exist now. Typically, the main_page value is the template name, so nothing needs to be configured at all.