I’m currently converting a personal project I’ve been working on to Sage 9.
I have a couple classes that I initialize and then global their variables in each template that I need them in, but using Blade I feel that there’s a better way to accomplish it.
Using Google, I came across https://stackoverflow.com/questions/29715813/laravel-5-global-blade-view-variable-available-in-all-templates which would let me use my variable across all blade’s without manually globaling them, but I’m curious if there’s a way with the current implementation to do something like this? I understand what they are saying and have done it before inside of Laravel, but I’m unsure how to accomplish it with Sage 9’s use of Blade.
Any insight on this would be greatly appreciated as I’d like to make everything as clean as possible.
Appears to work using init instead of after_setup_theme.
It looks like a decent amount of variables aren’t accessible inside of blades like sidebar.blade.php such as $post, $shortcode_tags, etc. so I’m guessing we just add them using sage('blade')->share()?
I also couldn’t figure out a way to get my comment template to render using blade inside of a Walker_Comment callback.
I tried \App\template(locate_template('templates/partials/comments-single-reviews.blade.php')); but since it’s not using include I’m unable to pass the variables inside of html5_comment. I tried putting them into an array and passing it with $data but they still weren’t accessible.
Any way to make this work or is it not sane since to do?
Editinit would be fine-- but it’s too soon to be able to get $post.
Edit 2after_setup_theme works fine. I just had it in an include that seemed to of fired it before blade was initialized. Still not able to get $post though.
While blade syntax and all possibilities it gives is great - wouldn’t switch back to plain old PHP on corner cases like Yours would be better time-wise?
I’m not on a time constraint with this project and am sucker for the clean code that is possible with Blade.
Most of the issues above have been solved other than the inability to fetch $post without globaling it (i.e. $GLOBALS['post'], but that is not a major issue by any means.
I know this is old, can you expand on how you solved this? For example, I have a variable that sets the template width and would like to print that out on all my containers. But, since I am pulling in nav, top, bottom, etc. seperate blade files, they don’t get the variable unless I place it individually within each file.