Laravel 6 view include from sub directory not working - laravel

I need to include two blade files navbar & sidebar (located in views/layouts/partials) in another blade template named admin.blade.php (located in views/layouts). So in admin.blade.php. I wrote
<div class="page-body">
#include('partials.sidebar')
<div class="page-content-wrapper">
<div class="page-content-wrapper-inner">
<div class="content-viewport">
#include('partials.content')
</div>
</div>
</div>
</div>
it gives me this error:
Facade\Ignition\Exceptions\ViewExceptionView [partials.navbar] not
found.
Can you help me? thanks in advance.

You should put layouts as part of the path, so your template code should be like below:
div class="page-body">
#include('layouts.partials.sidebar')
<div class="page-content-wrapper">
<div class="page-content-wrapper-inner">
<div class="content-viewport">
#include('layouts.partials.content')
</div>
</div>
</div>
</div>

Related

How to change which template is extended based on user authentication

I am using Laravel 6.20.11, and I have published the Laravel blade error templates. What I need to have happen is that if the user is authenticated, the error message extends the internal-only layout, and if not, it extends the public layout like so:
#auth
#extends ('int-layouts.partials.wrapper')
#section ('error')
<div class="be-content">
<div class="main-content container-fluid">
<div class="container py-5">
<div class="row">
<div class="col-lg-8">
<div class="text-block">
<h1>404 - Not Found</h1>
<p class="text-muted text-uppercase mb-4">Sorry, we couldn't find the page you were looking for.
Please contact the administrator<br/>
Or go back to the <a class="navbar-brand py-1" href="/controlpanel/">Dashboard</a></p>
</div>
</div>
</div>
</div>
</div>
</div>
#endsection
#endauth
#guest
#extends ('ext-layouts.master')
#section('error')
<div class="container py-5">
<div class="row">
<div class="col-lg-8">
<div class="text-block">
<h1>404</h1>
<p class="text-muted text-uppercase mb-4">Sorry,You are trying to reach the page that does not exist.<br>
Please contact the administrator <br/> Or go back to the <a class="navbar-brand py-1" href="/">Home Page</a></p>
</div>
</div>
</div>
</div>
#endsection
#endguest
The problem I am having is that when I test the 404 error using abort(404) or by trying to access a route that doesn't exist, the error message displays twice and the page inherits the int-layouts.partials.wrapper even when the user isn't authenticated.
Is this expected behavior or am I doing something wrong in my blade file?
You can try to use a conditional in one #extends directive:
#extends (auth()->check() ? 'int-layouts.partials.wrapper' : 'ext-layouts.master')
Then you can use a conditional after this inside your section.
#section('error')
#auth
#else
#endif
#endsection
The #extends directive is not actually returning output directly into the compiled result like most directives do. The compiled PHP for this is held in an array to be added later.
Everything inside the ( ) of the directive is being used as a literal to call make on the View Factory:
"<?php echo \$__env->make({$expression}, \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>"
If you found the compiled view for this Blade template you would see this:
<?php echo \$__env->make(auth()->check ? 'int-layouts.partials.wrapper' : 'ext-layouts.master', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
The first argument to make ends up being your view name when this compiled view is executed.
In Controller function:
$layouts = Auth::user->admin ? 'view.admin' : 'view.student'; //
view.admin or view.student is the blade file which you want to render
dynamically.
return view('welcome',compact('layouts'));
Write in Blade File:
#extends($layouts)
#section('...')
...
#endsection

I create a main page and all its code means header, footer etc i distribute in different pages

I create a main page and all its code means header, footer etc i distribute in different pages and i linked all pages with main page through include method...main page work properly except one code given below
main pages
<!doctype html>
<html lang="en">
#include('partails._header')
<body>
<!-- < navbar-->
#include('partails._navbar')
<!-- end navbar -->
<div class="container">
#include('partails._body')
</div>
<hr>
#include('partails._footer')
#include('partails._script')
</body>
</html>
folder name partials and _body i want to include in main page but not work
_body code is given
<div class="row">
<div class="col-md-4">
<div class="list-group">
First item
Second item
Third item
</div>
</div>
{{-- end 4 --}}
<div class="col-md-8">
#yield('content')
</div>
</div>
{{-- end row --}}
folder name partials and _body i want to include in main page but not work
_body code is given
<div class="row">
<div class="col-md-4">
<div class="list-group">
First item
Third item
</div>
</div>
{{-- end 4 --}}
<div class="col-md-8">
#yield('content')
</div>
{{-- end row --}}
If your body.blade.php is located in partials folder just include this way
#include('partials.body')
By saying yield('content') not working properly, what do you mean? How are you passing other view(blade) to the main page via content?

View [layouts.default] not found - Laravel

I am trying to run my laravel project but it showing error that view not found.
My welcome.blade.php file is
#extends('layouts.default')
#section('content')
<div class="slider">
<div class="img-responsive">
<ul class="bxslider">
<li><img src="images/slider/1.jpg" alt=""/></li>
<li><img src="images/slider/2.jpg" alt=""/></li>
<li><img src="images/slider/3.jpg" alt=""/></li>
</ul>
</div>
</div>
<div class="container">
<div class="text-center">
<div class="wow bounceInDown" data-wow-offset="0" data-wow-delay="0.3s">
<h3>Providing Our Clients</h3>
</div>
<div class="wow bounceInDown" data-wow-offset="0" data-wow-delay="0.6s">
<h2>Best & Creative Solutions</h2>
</div>
</div>
</div>
#endsection
Updated
you can see error here
file structure see here
Okay just looked at your folder structure, rename your layout folder to "layouts". hope that helps.

How can i access a div with almost all the parameters same

My HTML looks like this:
<div class="MainColumn">
<div class="firstrow">
<div class="sub1">Label1</div>
<div class="Value1">
<span class="ValueRow">
Linkname
</span>
</div>
<div class="Value1">...</div>
</div>
<div class="firstrow">...</div>
<div class="firstrow">...</div>
<div class="firstrow">...</div>
</div>
How can i click on the link named LinkName in the HTML above using XPath? I am working on Watir Webdriver.
Thanks for your help!
Locate it by link text and click:
browser.link(:text =>"Linkname").click
browser.a(xpath: "//a[text()='Linkname']").click

Looking for all descendant elements which parent does not have this css class

I am trying to get all children which has specific class and parent of this parent does not have a specific class.
I am trying a code like this, but it's not working.
$hrefs = $xpath->evaluate("//div[not contains(#class, 'tested-app-section')]/div[#class='product-container-body']/div");
Structure of the HTML I am working with and need to edit a little bit looks like this, other HTML content in <body> is irrelevant. (<body> contains more then just this block of HTML):
<body>
<div class="product-detail-section tested-app-section">
<div class="product-container-head"> ... </div>
<div class="product-container-body"> ... </div>
<div class="product-container-body"> ... </div>
</div>
<div class="product-detail-section publish-app-section">
<div class="product-container-head"> ... </div>
<div class="product-container-body"> ... </div>
<div class="product-container-body"> ... </div>
</div>
<div class="product-detail-section product-specific-section">
<div class="product-container-head"> ... </div>
<div class="product-container-body"> ... </div>
<div class="product-container-body"> ... </div>
</div>
I am trying to avoid in the result the very first <div> box (box with class "tested-app-section"), then I am trying to avoid everything witch class "product-container-head".
But I just cannot find a way how to do it.
Edit: So basically I am trying to get
/html/body/div[contains(#class, 'product-detail-section') AND not contains(#class, 'tested-app-section')]/div[not(#class='product-container-head')]
but this code doesn't return anything...
You are close, but missed a few things. Try this xpath expression and see if it works:
//div[not(contains(#class, 'tested-app-section'))]/div[not(#class='product-container-head')]

Resources