Open huubl opened 3 years ago
Hi @huubl
Thanks for your PR! I'm looking into this and I'm not sure this should be merged. As far as I know (haven't see it full focused), this will be a breaking change and as the templates are not blade files I don't think they have to be inside resources/views/tribe...
Maybe I'm wrong. Can we discuss this a little bit?
Hi @huubl
Thanks for your PR! I'm looking into this and I'm not sure this should be merged. As far as I know (haven't see it full focused), this will be a breaking change and as the templates are not blade files I don't think they have to be inside resources/views/tribe...
Maybe I'm wrong. Can we discuss this a little bit?
Nevermind, I've seen it and your PR doesn't break anything for people using previous versions as the default folders are still there. LGTM. Merging...
Ok @huubl one more question before merging out:
Should we use the v2 subfolder or maybe let the user to create the v2 folders in the resources/tribe folder. I mean, I have a project that overrides the single-event-blocks.php template and with your filter only templates in the v2 folder will be overriden. I think your change doesn't cover all use cases... ¿what do you think?
Ok @huubl one more question before merging out:
Should we use the v2 subfolder or maybe let the user to create the v2 folders in the resources/tribe folder. I mean, I have a project that overrides the single-event-blocks.php template and with your filter only templates in the v2 folder will be overriden. I think your change doesn't cover all use cases... ¿what do you think?
Good point. I think this filter only targets V2 templates. I will check if I can figure out how to target V1 and V2, maybe the other filter mentioned in the gist is necessary.
I'm going through this right now myself for a project and the quickest solution to allow full blade functionality was to use PHP2Blade to convert the views first.
Then, because their code checks for the folder / files before and include them manually instead of passing them to the WordPress template loader, it really limits our options. The php files really need to be there, so I create, for example, the "theme/tribe-events" folder and add "single-event.php" (or any other template) adding this piece of code. It could be extracted to be even more generic.
<?php
/**
* This code only takes the file name and passes it to Roots\view to load my "real" blade overrides that are located in resources/views
*
* @see resources/views/tribe-events/single-event.blade.php
*/
$basepath = str_replace(get_template_directory(), '', __FILE__);
$pathinfos = pathinfo($basepath);
$file = $pathinfos['dirname'] . DIRECTORY_SEPARATOR . $pathinfos['filename'];
if(\Roots\view()->exists($file)) {
echo \Roots\view($file)->render();
}
Except for the comment pointing to the right blade file, it can be copied and pasted in every file of the theme because it takes only the current PHP file path and name to route to the real blade view. It could even be used with any other plugin that doesn't respect WP's template functions. That's the "cleanest" I've been able to achieve this so far.
Hi,
Thanks for sharing this package. I try to make it work with blade files, but have not found a way to get this working. However I found a way to point the paths to 'resources/views/tribe/[..]'.