Closed raxan closed 10 years ago
This isn't currently possible, but that's an interesting idea. It could work very similar to folders, except if the folder template does not exist it would fallback to the default template directory. There are a few ways this could be done:
1. Add a flag to the addFolder()
method
This would use the existing folder functionality. Simply enable folder fallbacks by passing a boolean as the third value to the addFolder()
method (defaults to false
). This approach probably makes the most sense.
// Create new Plates engine
$themes = new \League\Plates\Engine('/path/to/default/theme');
// Add themes
$themes->addFolder('theme1', '/path/to/theme/1', true);
$themes->addFolder('theme2', '/path/to/theme/2', true);
2. Add a flag to the Engine
Instead of setting the third value on every addFolder()
call, simply set it once for the entire Engine
. I don't really like this approach since it doesn't leave the freedom to enable folder fallbacks on some folders and not others.
// Create new Plates engine
$themes = new \League\Plates\Engine('/path/to/default/theme');
$themes->enableFolderFallbacks(true);
// Add themes
$themes->addFolder('theme1', '/path/to/theme/1');
$themes->addFolder('theme2', '/path/to/theme/2');
3. Add a new addTheme()
method
A third option would be to create an entirely new method, which would essentially work exactly the same as the folders, except folder fallbacks would be enabled by default. While this approach is nice and clean for this particular use-case, I could see folder fallbacks being helpful in more situations than just themes. Further, this might create some confusion if behind the scenes they are treated as folders—meaning you couldn't have a folder and theme with the same name. If you didn't treat them as the same, then there is an issue with how to call them from the templates—currently folders use two colons (::
).
// Create new Plates engine
$themes = new \League\Plates\Engine('/path/to/default/theme');
// Add themes
$themes->addTheme('theme1', '/path/to/theme/1');
$themes->addTheme('theme2', '/path/to/theme/2');
Thanks! I will test!
Haha, I don't think I was very clear...this isn't currently possible. The three options I listed were simply my ideas of how Plates could be improved to support what you're asking for. I'm going to try and add this functionality into version 3.0.
LOL
In the fact yesterday before reply I was not read completely all message :) I understand that is not possible, but then I think that using "folders" feature exist a workaround.
Thanks for adding this feature!
Once this functionality is ready, the folder documentation should be updated accordingly. This can fall under a heading called "Theme mode".
This feature has been added (8a51dccbaa74addaed2bc73fff388b9c63dd88e0) and will be tagged with the Plates 3.0.0 release.
Hi I would like to ask if possible create child themes like wordpress.
Example:
Into folder "views" there is another folder "default" which contain all view and template files.
A designer can create another folder into "views/custom" for override some view/template files.
The template engine should check firstly on active theme (custom), and if not found the file view, then load from views/default folder.
Thanks