working with Laravel and I have following welcome page
</head>
<body>
</div><!--container-->
#include('partials._footer')
#endsection
#else
#section('fixx')
<p>Rivers</p>
#endsection
#endguest
</body>
</html>
and app.blade.php
#guest
<main class="py-4">
#yield('content')
</main>
#else
<main class="py-4">
#include('partials._nav')
#yield('fixx')
#include('partials._footer')
</main>
#endguest
_nav.blade.php
<link rel="stylesheet" href="{{ URL::asset('css/nav.css') }}" />
<div class="d-flex" id="wrapper">
<!-- Page Content -->
#yield('one')
#if('Auth')
#yield('two')
#endif
</div>
but when I see welcome page with logged user I could see #yield('one') contents in the #yield('two')
how could I fix this problem?
If you only want to show #yield('two') for logged in users, try this:
#auth
#yield('two')
#endauth
BTW, there are a few blade directives missing in your markup. Make sure you have a matching start and end tags for each directive you are using.
https://laravel.com/docs/blade#blade-directives
Edit:
If you want to hide #yield('one') for logged-in users:
// usign #guest
#guest
#yield('one')
#else
#yield('two')
#endauth
Related
#extends , #section and #yield work for the main welcome page, but I made a new product-gel.blade.php file in view and used the #extends and #section and #endsection on it but it doesnt seem to work.
Here is the yield place
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="..\resources\stylecss\style.css">
#vite(['resources/css/app.css', 'resources/js/app.js'])
<script></script>
</head>
<body>
<div id="app">
<section id="header">
<div class="main-pages-box">
<div class="main-pages">
CUSTOMER CARE
#if (Route::has('login'))
#auth
<a> {{Auth::user()->name}} </a>
LOG OUT
#else
LOGIN
#if (Route::has('register'))
REGISTER
#endif
#endauth
#endif
</div>
</div>
<div class="main-bar">
<div class="daraz-logo-container">
<img src="../resources/images/daraz_logo.png" alt="daraz_logo" class="daraz-logo">
</div>
<div class="search-box-container">
<form onSubmit="searching();">
<input type="text" placeholder=" Search on Daraz" name="search" class="search-bar" id="text-to-search">
<a onclick="searching();" class="search-btn"></a>
<img src="../resources/images/cart-icon.png" alt="">
<img src="../resources/images/downloadnow-icon.png" alt="">
</form>
</div>
</div>
</section>
<script src="../resources/scriptfiles/searching.js"></script>
#yield('content')
<section id="footer">
<div class="customer-care-end">
<h1>Customer Care</h1>
<ul>
<li>Help Center</li>
<li>How to Buy</li>
<li>Corporate & Bulk Purchasing</li>
<li>Returns & Refunds</li>
<li>Daraz Shop</li>
<li>Contact Us</li>
<li>Purchase Protection</li>
<li>Daraz Pick up Points</li>
<li>Fulfulled By Daraz (FBD)</li>
</ul>
</div>
<div class="codenthx">
<div class="QRcode"></div>
<div class="appdl">
<div class="QRthx"></div>
<p>Happy Shopping</p>
</div>
</div>
</section>
</div>
</body>
</html>
And here is the new file im trying to extend on (removed the html file and just put it a header testing file to see if it works)
#extends('layouts.frontend')
#section('content')
<div>
<h1>testing</h1>
</div>
#endsection
This works on the welcome.blade.php file but not on the product-gel.blade.php file.
this is what the directory is looking like for the welcome page
view > welcome.blade.php
and for the product one
view > produ > product-gel.blade.php
I have also tried moving the gel.blade.php file outside of produ folder like this
view > product-gel.blade.php
But that also doesnt work, I am still new to laravel so dont know what I am doing wrong here.
https://imgur.com/a/2crydOm
This is what it looks like.
I am trying to include this comments.index file:
#extends('posts.show')
#section('title', 'Comments')
#section('comments')
Create Comment
#foreach ($comments as $comment)
#if ($comment->post_id == $post->id)
<div class="border margin mb-1">
<div class="border margin">
<p>{{$comment->text}}</p>
</div>
Edit
</div>
#endif
#endforeach
Back
#endsection
From this posts.show file:
#extends('layouts.myapp')
#section('content')
<head>
<link href="{{ asset('css/posts.css') }}" rel="stylesheet">
</head>
<div class="post_container">
<div id="post_title">
{{$post->title}}
</div>
<div id="post_text">
{{$post->text ?? 'Empty'}}
</div>
<div>
<img src="{{ asset('storage/images/'. $post->image) }}">
<p>
{{$post->image}}
</p>
</div>
</div>
<div>
<h2>Comments</h2>
<div>
#include('comments')
</div>
Comments
</div>
Back
#endsection
Now the issue is that when I include 'comments' it throws 'view comments not found' error and asks if I am sure there is a blade file with such a name. This made me think that I need to include 'comments.index', but when I do this I get 'undefined variable $comments' error.
Doing an include of a partial is dot notation. So in this example...
#include( 'includes.modals.dude' )
This is really located in views -> includes -> modals -> dude.blade.php
The file name must be YourName.blade.php.
I think you are providing a relative path, include directive needs absolute path. So, in your case following code should work.
#include('comments.index')
I am trying to display comment index content
#section('title', 'Comments')
Create Comment
#foreach ($comments as $comment)
#if ($comment->post_id == $post->id)
<div class="border margin mb-1">
<div class="border margin">
<p>{{$comment->text}}</p>
</div>
Edit
</div>
#endif
#endforeach
Back
#endsection
From posts show file:
#extends('layouts.myapp')
#section('content')
<head>
<link href="{{ asset('css/posts.css') }}" rel="stylesheet">
</head>
<div>
<h2>Comments</h2>
<div>
#include('comments.index')
</div>
Comments
</div>
Back
#endsection
I want to be able to see the comments without having to go on comments.index link, which I have to delete.
It's only a blind guess: maybe you should look at your blade directory structure, where the file with the comments-section is located, maybe it should be
#yield('posts.comments')
And by the way the head tag in the content section looks a bit displaced imho.
The problem is that you are not yielding data here. You just include the value here. So use #include in stead of #yield. The following code is below:
In comment file :
Create Comment
#foreach ($comments as $comment)
#if ($comment->post_id == $post->id)
<div class="border margin mb-1">
<div class="border margin">
<p>{{$comment->text}}</p>
</div>
Edit
</div>
#endif
#endforeach
Back
Now in the From posts show file:
#extends('layouts.myapp')
#section('content')
<head>
<link href="{{ asset('css/posts.css') }}" rel="stylesheet">
</head>
<div>
<h2>Comments</h2>
<div>
#include('comments')
</div>
Comments
</div>
Back
#endsection
Laravel view page displays additional '<' character,but it is not given in the code. How can I fix it? I have given the blade.php code for the view. While inspecting, all the tags are misplaced and the head tag is shown inside the body tag.
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Laravel</title>
<!-- Fonts -->
</head>
<body>
<div class="flex-center position-ref full-height">
#if (Route::has('login'))
<div class="top-right links">
#auth
Home
#else
Login
#if (Route::has('register'))
Register
#endif
#endauth
</div>
#endif
<div class="content">
<div class="title m-b-md">
Laravel
</div>
<div class="links">
Docs
Laracasts
News
Blog
Nova
Forge
GitHub
</div>
</div>
</div>
</body>
</html>
I have these three blade templates
In my controller I'm calling dashboard view like this:
View::make('layouts.dashboard');
master.blade.php
<?= stylesheet_link_tag() ?>
<?= javascript_include_tag() ?>
<html>
<body class="fixed">
<div class="wrapper">
<div class="leftside">
#yield('leftside', 'left-side content')
</div>
<div class="rightside">
#yield('rightside', 'right-side content')
</div>
</div>
</body>
dashboard.blade.php
#extends('layouts.master')
#section('leftside')
#yield('sidebar', 'sidebar content')
#stop
sidebar.blade.php
#extends('layouts.dashboard')
#section('sidebar')
aaa
#stop
The dasbhoard blade shows properly in master blade, but sidebar blade doesn't want to show. Does anyone know what i'm doing wrong?
Thank your very much for any help :)
I don't think you can use yield() on a blade template that is not called.
Basically what you can do is make your master.blade.php into this
<html>
<body class="fixed">
<div class="wrapper">
<div class="leftside">
#include('sidebar') {{-- This is sidebar.blade.php --}}
</div>
<div class="rightside">
#include('dashboard') {{-- This is dashboard.blade.php --}}
</div>
</div>
</body>
</html>
Then, assuming that your are calling the dashboard.blade.php template, with both blade templates included. You can use the sections on either master.blade, or sidebar.blade inside dashboard.blade
#extends('layouts.master')
{{-- You can define now the sections available on master.blade and dashbard.blade --}}
OK I found out what was wrong :)
I called View::make('layouts.dashboard') instead of View::make('layouts.sidebar');