Blade template displaying HTML which has blade expressions in it

Viewed 23

I want to load the whole site content from a database, I got to the point when the HTML is perfectly showing with the {!! $content[0]["content"] !!}, but that HTML has other blade expressions in it, to get other data from other tables in the database and insert it into the site. And that part is showing too as plain HTML. Like in a table cell, instead of the value, I get this: {{ prices[0] }} Can you run the blade interpreter two times on load? Or what I want to do is a no-go and I need to figure out some other ways? I return to the view as return view('view')->with("prices",$prices)->with("content",$content);

Thanks in advance!

1 Answers

I'm not a Laravel person, but from what I know of templating languages, it sounds like you (or whoever originally wrote the code) might be trying to do too much using blade, and not enough using PHP.

If there are database queries being made, those probably shouldn't be made directly via blade files (and maybe cannot be), but should be made in a PHP file. This would be at the "M" or "C" level of the MVC pattern, depending on how strictly you want to adhere to that pattern.

You would then pass the retrieved values -- or, just as likely, PHP objects populated from those values -- to the templating layer, where your blade files live.

I hope that makes sense.

(Laravel people: Feel free to correct me on this if there's a convention that I'm not familiar with.)

Related