I want to show in my view one section if conditional is true, other section if it is false. I am using PhpStorm as IDE and what I get in those cases is that directive is not closed:
#if (conditional)
#section('content')
...
#stop
#else
#include('pages.something')
#endif
I am getting that opening #if is not closed, and that #else is missing opening directive.
Front-end works fine, but this is really bugging me in IDE. Can it be resolved?
EDIT:
This only happens when using conditionals and sections together. Conditionals and includes work fine.
Try to wrap your content using #yield
See laravel's docs for reference. https://laravel.com/docs/5.5/blade#template-inheritance
Related
I have the issue in which when I am writing the components in Laravel Mailable, according to their 6.x documentation (since my Laravel version is 6.0). But despite that, in the actual email some components render properly, some are just plain HTML. By plain HTML I mean the text literally says <a>...</a>, but doesn't render the actual element.
Why would that be? Maybe there is a bug, or I am missing something? I have written the most regular email with the components provided by Laravel's docs. There is no linter errors. The view is written in blade btw.
#section('content')
#foreach ($paragraphs as $item)
<p> {{ $item }} </p>
#endforeach
#component('mail::button', [ 'url' => $link ])
{{ $buttonText }}
#endcomponent
#endsection
I resolved the issue. The issue disappeared when I removed any possible indentation in the file.
When every single line started at column 0, the components rendered properly.
Documentation (at least 6.x) doesn't say anything about that, so I assume this is a bug with blade/php mailing compilation or something.
I started a laravel + vuejs project (fontend and backend in the same project).
It is basically a migration from a pure php-html project. I am wondering if it would be possible to migrate only a part of it, and to integrate the rest of it.
After your answers (thanks :) ), here is myview.blade.php:
#extends('template')
#section('contenu')
<div id="app">
#php
$path = public_path('myview/oldfile.php');
include($path);
#endphp
</div>
#endsection
Now I have an issue:
** Issue 1 **
I have this kind of code in the old php files:
<script type="text/javascript" src="./js/jquery-1.7.2.min.js">
but I also have scripts in my template (which contains the navbar and footer). Then of course I get this error
[Vue warn]: Error compiling template:
Templates should only be responsible for mapping the state to the UI. Avoid placing tags with side-effects in your templates, such as <style>, as they will not be parsed.
** Issue 2 **
$.post("./myview.php", "mode=activateForm&id1=<?=$id1?>&id2=<?=$_GET["id2"]?>", function() {
MethodNotAllowedHttpException
The POST method is not supported for this route. Supported methods: GET, HEAD.
The new issue is this, and I don't get why...
Any suggestions?
When you use #include in blade template it will look for the file inside of resource/views directory.
so use it like #include('posts/index').
where it will look for index.php inside of views/posts/ directory.
Do not use .php inside #include.
#extends('template')
#section('contenu')
<div id="app">
#include("yourDirectory/oldfile");
</div>
#endsection
Use the public path helper.
Put the files in your public folder and use public_path('filename.php'); in your include statement.
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()
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 conditions in blade and working fine but little bit worry if somebody comes and use inspect element so he can add href and link and make button as example working if it was disabled, so what is the good way to secure my code
#if (auth()->user()->customer->package_id>0)
<li class="btn_disabled"> Allready Purchased</li>
#elseif(auth()->user()->customer->package_id==null)
<li class="buttonprice">Purchase</li>
#endif