Ivan Gretsky Posted December 9, 2024 Share Posted December 9, 2024 Good day @teppo! Another question from me) I am building a solution based on PW and Wireframe, that needs the theming functionality. That is switching theme (default views) for all the views and components. Layouts and partials probably too. Is there an easy way to achieve this with current code? Maybe a couple of hooks? I can see two ways how it could work. Put `alternative-default.php` everywhere the `default.php` files are and somehow tell Wireframe to use those prefixed files. If there is another view except the default one, the prefix should work as well. Like `alternative-json.php`. Probably an option should be available whether to fallback to defaults without the prefix or not. Create an overrides or theme folder somewhere and have somehow point Wireframe to use views from there. For my personal need the 1st approach seems to be a better one. But just maybe it is easy enough to provide possibility for both? Thanks! 1 Link to comment Share on other sites More sharing options...
teppo Posted December 12, 2024 Share Posted December 12, 2024 Hey Ivan, I'll have to get back to this later, but just wanted to say that this is an interesting idea. I've never really gone further than specifying a different layout file for different themes — so basically they've all had their own layouts, styles, etc. but still shared the same template specific views. And had a shared pool of components and partials. Both of your ideas sound feasible, but I must admint that the overrides/theme folder sounds "cleaner". It would probably be conceptually similar to WP child themes, e.g. you can override some features, but those that have not been overridden are the same as in the "parent theme" — right? That being said, the first one sounds like an easy to implement thing as well. I'll have to take a closer look at the code to be sure. 1 Link to comment Share on other sites More sharing options...
Ivan Gretsky Posted December 12, 2024 Author Share Posted December 12, 2024 1 hour ago, teppo said: you can override some features, but those that have not been overridden are the same as in the "parent theme" — right Yes. But I think there could be an option to either use parent's features or to indicate that this one is yet to be implemented in a theme (through an error or warning). Link to comment Share on other sites More sharing options...
Ivan Gretsky Posted December 12, 2024 Author Share Posted December 12, 2024 1 hour ago, teppo said: hat being said, the first one sounds like an easy to implement thing as well. I'll have to take a closer look at the code to be sure. Great! Looking forward to see it in Wireframe! Thanks for your work and talent! Link to comment Share on other sites More sharing options...
Ivan Gretsky Posted December 12, 2024 Author Share Posted December 12, 2024 (Deleted) Link to comment Share on other sites More sharing options...
Ivan Gretsky Posted December 24, 2024 Author Share Posted December 24, 2024 @teppo, just in case you are in doubt what is that what you can gift to the world this New Year, I am quite sure the world will be delighted with the new Wireframe version with themes support)) Well, maybe not the whole world, but certainly some minor parts of it))) I do not know how do to say "happy upcoming New Year" in English or Suomi, so I'll put it here in Russian: "С наступающим!" 1 Link to comment Share on other sites More sharing options...
teppo Posted December 30, 2024 Share Posted December 30, 2024 @Ivan Gretsky, just wanted to let you know that I'm currently working on the theme feature, but it will require a bit more testing at least. Admittedly this was a bit more complicated than I had originally assumed. That being said, I've just pushed an initial version with a new "view prefix" feature to dev branch, in case you have time / want to give it a try: https://github.com/wireframe-framework/Wireframe/tree/dev. This is pretty much the first option that you described. I ended up rewriting it a couple of times, though, but hopefully have now landed on a solution that makes sense. View prefix can be set in a couple of different ways, but likely the easiest is calling Wireframe::setViewPrefix() in the bootstrap file (wireframe.php): // init Wireframe $wireframe = $modules->get('Wireframe'); $wireframe->init(); // if we're on a theme page, set view prefix if ($page->template == 'theme-home') { $wireframe->setViewPrefix('theme/'); } // render the page echo $wireframe->render(); View prefix will be used whenever Wireframe is rendering a (template/page) view file, component view file, or partial file. It should also work with separate renderer modules, but that's not something I've yet had a chance to test. At least for now default view files are used in case a prefixed version doesn't exist. This could be made configurable, but it felt more intuitive to me that this is (at least) the default behaviour. Note that in the example above I've intentionally used a prefix that is a path, e.g. has "/" — it's not necessary to use a path, it could just as well be something like "alternative-" 🙂 And a big, big warning at the end: I quite literally got this thing up and running half an hour ago. I've done very little testing, so it's entirely possible that there are still issues with it. I hope to get back to it and test properly soon. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now