Best Practice / Resources for Blade

sage9
blade

#163

Use a static function so you can run a function within each layout.


#164

Thanks for the response.

I noticed that same variable values are being displayed on different flexible content rows; despite the values in the backed of WP.

How would you go about creating a unique variables inside of the flexible content loop with the controller?


#165

Hey did you end up using this way of getting the name of the current blade template? Because I tried to implement it the exact same way (also using barba.js in my project), but I can’t get it to work. I get the error message “undefined variable: current_template in …/wp-content/uploads/cache/350a511d5b8c77023912d976ba1f2ffcdbf847ee.php”.

I added the filter in “my-theme/app/filters.php”. Maybe I’m missing something?! A pointer would be much appreciated!

sage version: 9.0.1


#166

Are you using Controller?

You should be able to add this to App.php if you’re using Controller.


#167

Hey, I already updated to “soberwp/controller”: “2.0.1” and followed instructions from other threads for the changed file names etc. So I’m able to get data of simple strings with the controller into my views, but not really sure how to use the filter for the name of the current blade template with the controller. That’s why I tried to use the filter method in “app/filters.php”.


#168

That’s a good usecase, got some work to finish up, but I’ll take a look at a nicer way of doing this via the App Controller this evening.


#169

@williharder this is quite an easy fix for Controller, so I’m going to push a new version over the weekend.

It will solve this https://github.com/roots/docs/issues/150 and https://github.com/soberwp/controller/issues/80

So in summary add_filter should work again as expected.

Update: Pushed to dev-master for testing.


#170

@williharder to take this further, the next release (which I’ll tag in the next few hours), is going to have a __before (and __after) method which will allow you to interact with Controller params. One of them, is

protected $template; 

So in your specific Controller, you could use this lifecycle event

public function __before()
{
    var_dump($this->template);
}

#171

I hadn’t needed to learn too much about Blade to stay fairly DRY until now. So I watched the Blade section in this tutorial, and 30-60 minutes of taking notes and watching was so worth it. Really cleared up a couple confusions I had w/ Blade.

I’ve done this guy’s tuts before (on Udemy for Vue.js), and he is one of my favorites.

Pluralsite isn’t free, but they do have free trials (no affiliate link or anything sneaky):


#172

Thanks, I was also looking to learn better practices, will definitely check out.


#173

I also found some blade tutorials on Laracast. Components and slots is a cool feature that is probably overlooked but most: https://laracasts.com/series/whats-new-in-laravel-5-4/episodes/6