Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

folder fallback not working as expected for "theming" render/layout #234

Closed
ghost opened this issue Dec 4, 2018 · 6 comments
Closed

folder fallback not working as expected for "theming" render/layout #234

ghost opened this issue Dec 4, 2018 · 6 comments
Milestone

Comments

@ghost
Copy link

ghost commented Dec 4, 2018

I followed the Simple example and tried to add "theming" from the Folders documentation.

It makes the most sense to add template.php to the theme1 folder to point to a different CSS file.

$templates->addFolder('theme1', '/path/to/theme/1', true);
echo $templates->render('theme1::profile', ['name' => 'Jonathan']);

However, this does not work. It will try to locate profile.php in the /path/to/theme/1, which fails, so it falls back to the default path where it finds profile.php. However, profile.php contains this call:

<?php $this->layout('template', ['title' => 'User Profile']) ?>

This again takes the "default" template.php instead of the one from theme1. I'd also have to modify the call the layout to point to theme1::template which then does work... But then it is not easily configurable from your controller...

So it seems the only way to make this work is to create a "full" theme, i.e. copy all templates in the directory of the theme, except the ones that do not reference other templates... So here I'd need to copy profile.php to the theme1 folder as well, even though only the layout call would be different...

Is there any other way to make this easier without needing to duplicate templates you don't want to modify in your theme?

@ragboyjr
Copy link
Contributor

ragboyjr commented Dec 5, 2018

@fkooman this is a great discovery. I think this might do well with a proper theme extension that would allow you to set a theme variable for plates and it'll be used as context when fetching products.

So, implicitly ever call to a template file would check for the currently set theme and fallback accordingly.

@ghost
Copy link
Author

ghost commented Dec 12, 2018

How would one go about this? I've been looking at it for a few hours now and I don't really understand how to override the calls to "render" and "layout" from an extension to make it consider the "theme" path...

My approach was to try and call setDirectory from the extension to the theme path if the template exists in the theme directory, otherwise do nothing...

@ghost
Copy link
Author

ghost commented Dec 13, 2018

It turns out it is not that difficult to write a more or less compatible Plates implementation that does work with "themes", i.e. allows you to specify a list of folders where it starts looking in the first one and 'falls back' to the later ones...

https://gist.github.com/fkooman/6942065e6dd3ad2c540349f3e6dba6f6

@ragboyjr
Copy link
Contributor

Good deaal @fkooman will check this out when I get bit more time. Little slammed during holidays

@ragboyjr
Copy link
Contributor

When I think this through, I wonder if the component system will better tackle this type of issue. I'm going to attach this to the 3.5 milestone for now and see if this something that we can look at then.

@ragboyjr ragboyjr added this to the 3.5 milestone Dec 23, 2020
ragboyjr added a commit that referenced this issue Jan 9, 2021
- Added support for themes
- Added support for ResolveTemplatePath
  as a way for more complex path resolutions
  for templates

Signed-off-by: RJ Garcia <ragboyjr@icloud.com>
ragboyjr added a commit that referenced this issue Jan 9, 2021
@ragboyjr
Copy link
Contributor

ragboyjr commented Jan 9, 2021

Theme support has been merged to master!

@ragboyjr ragboyjr closed this as completed Jan 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant