laravel5.1 - blade template not rendering - php

I have tried all in this link :
php laravel blade template not rendering
My codes are here.
my views/layouts/master.blade.php file contains
<html>
<body>
#section('sidebar')
This is the master sidebar.
#show
<div class="container">
#yield('content')
</div>
</body>
</html>
my views/child.blade.php file contains
#extends('layouts.master')
#section('content')
<p>This is my body content.</p>
#endsection
my route.php contains
Route::get('blade', function () {
return view('child');
});
from my browser I typed in :
http://localhost/larablog/public/blade
The output is a blank page.
I tried with non blade pages and it worked, I also passed normal variable to non blade pages which also worked. When I try with blade templating, the page seems to be blank always.
Please let me know where I went wrong.
Thanks.

As in the following link
Proper laravel storage permissions
I had a permission issue at
storage/framework/views folder.
I changed the folder permission to 777 and it all solved the issue.

May be Problem is with the routing
Route::get('/blade', function () {
return view:('child');
});

If you're running on apache make sure the web server has write permission to the storage directory.

Related

How can I overcome Laravel 8 template system problem

In layout folder I have a file named "app.blade.php". To render some content from other balde file I wrote in the file
#yield('content')
I created another file in "views/admin" name "dashboard.blade.php". Written code in this file is
#extends('home')
#section('content')
Test text
#endsection
But content doesn't load in "app.blade.php" file thus nothing in
#yield('content') section
What to do?
update this
#extends('layouts.app') <---------- it will extend app.blade.php then inside that section will render content
#section('content')
Test text
#endsection
ref link https://laravel.com/docs/8.x/blade#extending-a-layout
Error Identified and solved
You said that content does not load in app.blade.php but you have extends the home page.
Update your script like this->
#extends('layouts.app')
#section('content')
Test text
#endsection
I think you got where you made the wrong. Let me know about the updates

How to add php old code in php blade view

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.

Blade does not seem to work (maybe "extends")

I know it's not a specific question, but that's because it's the only info I have about my problem.
For some reason, my blade templates do not seem to work.
Folder structure:
resources / views / layouts / master.blade.php
resources / views / child.blade.php
master.blade.php:
<p>Some content here</p>
#yield('content')
<p>Some additional content here</p>
child.blade.php:
#extends('layouts.master')
#section('content')
<p>This is the user content</p>
#endsection
My expectations are:
Some content here
This is the user content
Some additional content here
What I get is:
Some content here
Some additional content here
So my content section is not showing up at all.
I am using Laracast and Laravel v5.7.8
I also set up a new laravel application in different versions (5.1.* - 5.7.8) but in every new application it didn't work.
I think it can't be an issue with my files. Let me tell you why:
The welcome.blade.php shows a login button if Route::has('login').
If I add a login route it doesn't show aswell and I didn't edit the welcome page. And it does not work in new laravel applications aswell.
I don't got a clue why this is...
Thanks for any help.
And yes, I've done my research for a couple of hours now.
For the order you mentioned you just need to move your yield below the paragraph, like this:
<p>Some content here</p>
<p>Some additional content here</p>
#yield('content')
Notice how #yield is the below these 2 paragraphs, with this you get the desired output
I got it now. The routes where wrong and nothing with my files.
What I did was:
Route::get('/', function () {
return view('master');
});
This is of course wrong and what it should be is:
Route::get('/', function () {
return view('child');
});
I've looked through the files many times and didn't notice it...
It's just some of those days :D.
Still, thanks to anyone who tried to help.

Laravel master page not working

I am working on my master page which is currently not working. In browser it returns:
#layout('master') and not key as specified.
code in routes.php
Route::get('/', function()
{
return View::make('index');
});
code in view: index.blade.php
#layout('master')
#section('container')
<h1> Hey </h1>
#endsection
code in view: master.blade.php
<div class="container">
#yield('container')
You need to use #extends('master') in L4 and have it right at the top of your file.
I mean RIGHT at the top, line 1, with no white space around it. This use to be a problem in L3, not sure if it also is the case for L4.
replace #layout with #extends
refer http://laravel.com/docs/templates#blade-templating for Using A Blade Layout

#extends('layout') laravel. Blade Template System seems like Not working

I tried to use the laravel's template system: blade but seems like not working when using the code below in the file users.blade.php:
#extends('layout')
#section('content')
Users! #stop
and browser,
#extends('layout')
That should work if you have a template file at /app/views/layout.blade.php that contains
<p>Some content here</p>
#yield('content')
<p>Some additional content here</p>
Then in your /app/views/user.blade.php, the content
#extends('layout')
#section('content')
<p>This is the user content</p>
#stop
If you call return View::make('user') you should have the compiled content
<p>Some content here</p>
<p>This is the user content</p>
<p>Some additional content here</p>
I hope that helps clarify things for you. If not, can you provide your template file locations and the relevant content?
Just remove the extra space or anything before #extends('yourlayoutfile').
It should be the first thing to be rendered in the file.
I was facing the same problem and tried many things.Suddenly I found a single space at the starting of the file before #extends.
Removed the space and is working fine.
Thanks.
Format:
#extends('layouts.default')
#section('content')
.....
#stop
---Edit----
If this didnt work then try :
Copy all the content in the file and then delete the file.
Create a new file and save it as filename.blade.php
Only after saving the file paste the content into the page.
Save the changes and run it.
This works.
Thank you.
Where is your layout?
If its in app/views/layouts, then it should be
#extends('layouts.index')
(assuming the name is index.blade.php)
ex: #extends('layouts.foo') equals a file in app/views/layouts/ called either foo.blade.php or foo.php. (depending if you use blade)
I have the same problem. What is did is:
1. in routes.php
Route::get('about', 'AboutController#index');
that
AboutController is a controller file AboutController.php in app/controllers
index is a function inside that controller.
2.Create AboutController.php in app/controllers
class class AboutController extends BaseController {
protected $layout = 'layouts.default';
$this->layout->content = View::make('pages.about');
}
You can look at this reference: Defining A Layout On A Controller
By default,Laravel has a layouts folder inside views folder, i.e. app/views/layouts and in this folder you keep your layout files, i.e. app/views/layouts/index.master.php and if you have something similar then you should use something like this:
#extends('layouts.master')
#section('content')
<p>Page Content</p>
#stop
This will inherit/use the master.blade.php file (as layout) from layouts folder, here, layouts.master means layouts/master.blade.php.
In your master.blade.php file you mast have this
#yield('content')
So, data/content from the view between #section('content') and #stop will be dumped in the place of #yield('content') of your layout.
You can use any name for your layout file, if it's layouts/main.blade.php then you should use
#extends('layouts.main')
Make sure you inserted the css link in App.blade.php
For me By default there is no link to the css file
Insert the following link in app.blade.php
<link rel="stylesheet" href= "/css/app.css" >
now its works fine :)
list things to make sure
file name and path properly given
double-check .blade.php file extention
layouts.admin.blade.php
<section class="content" style="padding-top: 20px">
#yield('content')
</section>
#extends('layouts.admin')
#section('content')
<p> this is Order index view</p>
#endsection
Try this!
php artisan cache:clear
php artisan view:clear
php artisan route:clear
php artisan clear-compiled
let's say you have 'master.blade.php' and 'index.blade.php'.
and both of files are in views->home directory. when you want to use #extends in 'index.blade.php' by calling 'master.blad.php' , you should write in index.blade.php file this statment:
#extends('home.master')
not
#extends('master')
Simply save your source using encoding UTF-8 without signature.

Categories