I have this in my blade file:
#if(Session::has('logged'))
#include('layouts.usernav')
#else
#include('layouts.publicnav')
#endif
When I run my page, it is just a blank page.
When I change it to look like this:
#if(1 == 1)
#include('layouts.usernav')
#else
#include('layouts.publicnav')
#endif
My page gets displayed. I don't know what I am doing wrong. What would/could be causing this?
Related
I am trying to pick the master blade template dynamically as per the current user roll logged in. (here it should go to the 'shopowner' auth block)
#auth('shopmanager')
#extends('theme::Admins.shopmanager.layout.master')
#endauth
#auth('shopowner')
#extends('theme::Admins.shopowner.layout.master')
#endauth
but this always gives error as it tries to compile the 'shopmanager' master template. It is not going into the 'shopmanager' #auth block because it's not printing anything if I print inside that block.
It only works if I completely comment out that line.
P.S.:
This is the master theme::Admins.shopmanager.layout.master template file
which must not be loaded.
#extends('theme::Admins.outline.layout.master')
#include('theme::Admins.shopmanager.layout.common.header')
#include('theme::Admins.shopmanager.layout.common.left-sidebar') // The error throws from inside this view.
#include('theme::Admins.shopmanager.layout.common.footer')
#section('title-head', __('Shop Manager'))
I can wrap the #auth check around #include lines but the point is, this complete file should be skipped from the compilation.
SOLVED
As per my learning, #extend(...) will always be compiled regardless of outer wrap conditions. so must be moved to dynamic variable based blocks.
#auth('shopmanager')
#php
$masterTemplate = 'theme::Admins.shopmanager.layout.master';
#endphp
#endauth
#auth('shopowner')
#php
$masterTemplate = 'theme::Admins.shopowner.layout.master';
#endphp
#endauth
#extends($masterTemplate)
Try below code ,i hope this ans help you:
#if(Auth::check())
#if(Auth::user()->role=='shopmanager')
#extends('theme::Admins.shopmanager.layout.master')
#else
#extends('theme::Admins.shopowner.layout.master')
#endif
#endif
If you have multi-authentication that time try below :
#if(Auth::guard('shopmanager')->user())
#extends('')
#else
#extends('')
#endif
In my case, I'm handling manager, customer and admin with this code.
Manager : Auth::guard('manager')->user()
Admin : Auth::user()
Customer : Auth::guard('customer')->user()
Hi all i will be needing an assistance. I have a navbar that all link on my app use but i will like to seclude a search form from some of the link in the app but am having difficulty doing that. This what i have tried on my nabvar so far example
Tried using route but no success
#if( (route('portfolio') &&(route('portfolio.details)
content here
#else
content
#endif
then i tried targeting the URI
#if( Request::is('/portfolio') &&(route('portfolio/details)
content here
#else
content
#endif
None seems to working.
I don't think you should be using the route helper method in your if statement. I think if you just do something like this, it should work.
#if (request()->is('portfolio'))
content
#else
content
#endif
hi sorry for my language.
im using laravel 5.6 to create a simple article site.
i have a problem with show article comments as string. the problem is : laravel try to render php codes and the page give me some errors.
imagine a user wants to send his laravel code as comment to me:
(this is just an example)
#foreach($article->tags as $tag)
<a class="tags" href="/tags/{{ $tag->slug }}">{{ $tag->title }}</a>
#endforeach
if user send this codes as comment to me, my page not loading and give me errors
my code to show comments :
{!!$comment->body !!}
help me please . thank you
Replace {!!$comment->body !!} with {{$comment->body }}.
When you use {!! !!}}, the template engine tries to parse the contents within the braces. Use {{ }} so that the contents are displayed as it is escaping all html.
i found the problem :
problem is for laravel blade codes.
like: #foreach . #if . #auth and ....
i have to scape this codes with space :
# foreach . # if and ....
How would you do this using blade's #import method? I've tried:
#if (#include('/path/to/phpfile'))
#include('/path/to/phpfile')
#else
<h2>Oops! It doesn't look like this page exists!</h2>
#endif
also tried with file_exists(), no dice :(
You may try this:
#if(View::exists('viewname'))
#include('viewname')
#endif
With blade, it is possible to show a default value if there is no data to #yield, like so:
#yield('section', 'Default Content');
But I would really like to show a view instead of a string text. The reason is that I want to #yield a navigation menu into a layout. Most of the times the navigation menu will be exactly the same, so a default option of some sort should be optimal here, but I would like a way to override the menu.
Is it possible to achieve this?
To check if the section exists you could use:
array_key_exists('fooSection', View::getSections())
and to check if the section is empty you could use:
empty(View::getSections()['fooSection'])
For example:
#section('fooSection')
Foo
#stop
#section('barSection')
Bar
#stop
<h1>If Section Exists</h1>
#if (array_key_exists('fooSection', View::getSections()))
#yield('fooSection')
#else
#yield('barSection')
#endif
<h1>If Section isn't Empty</h1>
#if (!empty(View::getSections()['fooSection']))
#yield('fooSection')
#else
#yield('barSection')
#endif
Hope this helps.