I have a header.blade.php in an includes folder, this header page is the whole webpage base. i have links on it and i have the header of the website which is included in all other web pages.
The heading part i want to retrive just the first line of the table result in it so the admin can update that line whenever possible.
The thing is that it is hard to figure out a route to give to it as it is a partial page.
The code on it is:
<div class="site-heading" data-webid="{{ $web_header->id }}>
<h1>{{ $web_header->header }}</h1>
<hr class="small">
<span class="subheading">{{ $web_header->slogan }}</span>
</div>
My home controller has the following code to display in the information on the header partial page:
public function showWebHeader()
{
$web_header = WebHeader::all()->first();
return view('include/header', [
'web_header' => $web_header
]);
}
I am lost and confused here because I keep getting undefined variable on every single page I have on my web system.
Related
Issue:
I am trying to parse an HTML string inside a blade template and then once the blade template is build, it get passed into a slot inside Vue.
example.blade.php
<p>{!! $market['description'] !!}</p>
Example.vue
<div class="d-none d-md-block">
<slot name="description"></slot>
</div>
Right now, when I click refresh it actually parses the HTML string and displays it correctly. And then once the blade template is injected into the slot in the Vue file, it goes back to an HTML string.
I hope this explanation makes sense. Let me know if you have any questions. Also, edits for the wording of the title are welcome.
main page -> welcome.blade.php
#extends('layouts.footer_back_to_top')
#section('footer_back_to_top')
#endsection()
footer page -> footer_back_to_top.blade.php
<p id="back-top">
<span></span> Back to Top
</p>
#yield('footer_back_to_top')
The question I want to ask is without using #yield('footer_back_to_top') still will display the result?
No, result won't be displayed. You should use #yield to make this section displayed and in child view you normally define #section where you define what should be displayed.
I recently started to build a Laravel/blade web application and I want to switch between what my layout view is showing. I want to replace 'content' with some other blade.php view when I press a button in the layout file. For example in ReactJS you can just determine the rendered content with an IF statement and some vars.
<div class="container">
#yield ('content')
</div>
I googled a bit but couldn't find a straight forward solution so I wondered if this is common in Laravel or do you just have to make a lot of different layout files with other #yield('...')? A lot of code would be duplicated right?
You can use conditional blade directives
#if(Session::get(user_type') == 'Admin')
#extends('layouts.admin')
#else
#extends('layouts.normal')
#endif
#section('title')
#endsection
#section('content')
etc ....
I have the site with the structure like:
First: master.blade.php : this contain section('content')
<body>
#include('partial.header')
#yield('content')
#include('partial.footer')
</body>
Second index.blade.php : contain section('content').
#extends('layouts.master')
#section('content')
<div id="container">
<div id="news">
#yield('news')
</div>
<div id="apartment">
#yield('apartment')
</div>
</div> <!-- ./container -->
#endsection
Third: news.blade.php : this simple to show all news
#foreach($posts as $post)
#endforeach
Final file: apartment.blade.php : this simple to show all apartment.
#foreach($apartments as $apartment)
#endforeach
My route direct to master.blade.php.
My question is:
When I include news with #yield('news') in index.blade.php. It shows correct all news in my database.
But when I delete #yield('news') in index.blade.php. It also show news from my database (but it's lost css/js for that).
Why I deleted #yield('news'), it's should don't show any news on my page?
Seem Laravel Blade not support two #yield in #section. When I add only 1 row #yield('news') into index.blade.php file. It shows list news on my index page. When I continues add #yield('apartment'). Don't have any apartment shown on the index page. I certainly it has values when foreach to get data. I also test with HTML statics but don't have anything changes.
My route direct to master.blade.php.
Index extends master, so point your route to index view.
If sections continue to be yielded, after #yield removal, I think the framework is loading a cached view.
Try clearing the view cache php artisan view:clear or use php artisan --help view:clear for help.
Also #yield yields a section in a parent child relationship.
Change yields to include like #include('partial.news') if news are in partial folder or to whatever the path. Rendering could be manipulated using #isset or #empty statements or even #forelse loops.
Blade Control Structures.
I have a question: how can 1 view/page use 2 controllers to display different data?
For example:
1) Page displays DVD's information using DvdController.
2) On that same page I want to use a Template/Partial view, that displays list of actors, and that list should come from the second ActorsController.
I can add a template view inside another page but the second controller doesn't work:
MainPage on URL: website/dvd
{% block body %}
<div>
<h1>{{ dvd.title }} </h1>
</div>
<div>
{{ include('DVDBundle:Actors:actors.html.twig') }}
</div>
{% endblock %}
Above I use the partial view actors.html.twig to show the actors, strangely the html code/div's and so on are actually displayed and working on the page, however the controllers(ActorsController) method that meant to return this partial view is not executed for some reason.?
But if I go to the view directly via link: website/actors then its working.
The Symfony documentation on embedded controllers explains this nicely.
In short, you will need to do something like this in your template file:
<div>
{{ render(controller(
'DVDBundle:Actors:actors',
{ ... parameters to the controller action here ... }
)) }}
</div>
The important thing is calling the render function, which allows a controller to be rendered, as opposed to simply includeing a template. (This assumes that your have an ActorsController with an actorsAction method; change the names as appropriate to your controller.)