Laravel view not rendering correctly - php

I am trying to add a new view to my laravel project, and it is just dumping the entire content on the page, including my blade code, instead of executing said code. For example, my page in the browser is this:
#extends('user.layouts.app') #section('title', 'New Reminder') #section('content')
New Reminder
#csrf
Title
Content
#endsection
When it should obviously be executing that code, not putting it on the page.
I have tried clearing the routes, and researched around but no dice.
I am calling this view the same way I am calling others in my code - in the controller like this:
return view('user.partials.stat_types.new_type');
Any help or advise is appreciated!

You must have the file name with the extension .blade.php if you want Blade to be used to compile the view. With just .php the PHP engine is used.
Change your view filename to have the .blade.php extension.

Related

Laravel 4 displays php tags (#extends) on web page as a string

I'm new to Laravel and I've just started my first project using WAMP, however, the special php tags, (#section, #extends, #stop), and all the other tags are displayed as a string.
I've switched Laravel's error variable to true and it still comes up as a string. I've checked Laravel's welcome.blade in my browser and although the html and css are working fine it displays the # tags. I've also tested the server by including and that works fine. I've checked everywhere online and there's no answers to this problem.
Here's an example:
#extends('layout')
#section('content')
Users!
#stop
This displays:
#extends('layout') #section('content') Users!
Any help please?
If you have blade file in a folder you need to add a folder name in extends
#extends('folder_name.layout')

How to call ...blade.php in different folder inside views folder in laravel

Excuse me, i would like to ask about how to call another page blade in different subfolder inside views.
Example :
views
--home(subfolder)
--beranda(subfolder)
--refresh.blade.php
--layouts(subfolder)
--master.blade.php
in master.blade.php implements template page, when i click one link in this folder may have to go in refresh.blade.php.
Likely another web layout, they have a lot of link in header like 'Home', 'Paper', etc.
I'm still learned more about laravel as beginner practice.
May you can help me, i'll appreciate that.
Regard, Aga.
I think you can refer to some directives such as #include and #extends in the laravel blade.
For example, in the admin.common.header view (located at admin/common/header.blade.php), we have some basic page code (common to various pages such as navigation bar or layout). We use #yield such as #yield ("extra_js") or #yield ("extra_css") where we want to add code later.
header.blade.php
<html>
<head>
something maybe ...
#yield("extra_css")
</head>
<body>
something maybe ...
#yield("extra_js")
</body>
</html>
And in another view such as admin.feedback.feedback, you can use #extends('admin.common.header') at the top of the code to inheritance the template and you will get the layout of this template.
For different content in the feedback template, you can use #section to give you code to fill in the inheritance template such as #section('extra_js').
feedback.blade.php
#extends('admin.common.header')
#section('extra_js')
<script> something... </script>
#endsection
If you want to include one blade, just use #include.
<div>
#include('shared.errors')
<form>
<!-- Form Contents -->
</form>
</div>
In laravel blade there are many instructions to complete the rendering of the template, if you want to know clearly, please refer to the corresponding version of the official document.

Laravel Blade : Not all properties go through to certain mini-views using #yield

I am working with Laravel and created a master.blade view file to use on all my pages.
The master view yields mini-views inside.
On most mini-views everything works fine, but on some, I don't get the background image from the master.
The problem is I still get the nav-bar and the footer on those pages, which means they do recognize the master view.
What can be the reason for that?
On all pages I use the exact same way to include and to yield:
#extends('master')
#section('content')
#endsection
Thanks alot!
Just use full path to your file, start with /

Laravel 4 blade template won't render whole page

I'm running into a weird issue where my page isnt' getting rendered in its entirety. The bottom bit is getting cut off and I'm not sure why.
I'd paste code, but it's a 3000+ line template im trying to implement.
I am doing it as follows in dashboard.master:
#include('dashboard.master.head')
...
#include('dashboard.master.header')
...
#include('dashboard.master.sidebar')
...
#include('dashboard.master.style_customizer')
...
#include('dashboard.master.page_header')
...
#yield('content')
...tons of lines here
It renders up to content correctly, and awhile after that but it seems to stop at some point.
example of my blade file calling my master
#extends('dashboard.master')
#section('content')
<p>This is my content</p>
#stop
Edit:
I tried removing everything and just pasting the HTML template I have. It still just stops rendering towards the end of the page. So all I have now is literally the master file and the includes in my blade template that calls the master.
Laravel will maintain a cache of views that have been accessed, just so that it doesn't have to compile the blade template for each page load. It should be refreshing a particular view should it change, but it sounds like, for some reason, the cache wasn't being refreshed.
You can clear the view cache in two different ways:
# Method 1
php artisan cache:clear
# Method 2
rm `ls /path/to/application/app/storage/views | grep -v '.gitignore'`
Reference
In order to show all page, change your last code to :
#extends('dashboard.master')
#section('content')
<p>This is my content</p>
#show

How do you include PHP files in the view file of a Zend/MVC?

Maybe I dont understand the MVC convention well enough, but I'm trying to include a file to the index.phtml view for the main Index Controller, and it keeps giving me an Application Error. I have no idea what this error is or why its not working. But I'm using a standard include_once(...) in the view.
Is this even allowed?
A view in Zend is still just a php file. If you are getting errors in a view using include_once(), they are probably because the file you want can't be found in your include path. Trying dumping get_include_path() into the view and you will see what directories PHP is searching to find your included file.
As an alternative to include_once, you could use
<? echo $this->render('{module}/{action}.phtml') ?>
to pull in the file.
There are partial views for such purpose
http://framework.zend.com/manual/en/zend.view.helpers.html (ctrl+f Partial Helper)
The view is only the HTML that will be rendered. It's the very last thing that is processed. The controller is called first, then it calls whatever models are needed within. After passing all the data to the view, the view's HTML is rendered.
In short: whatever you include in the view, the controller isn't aware of it. You need to run your PHP includes earlier in the code. If you do it in the controller, it should work OK, I suppose (not tested, so I don't guarantee anything).
You can use Zend View Helpers for this purpose
last time this works fine for me. You can try this:
<?php echo $this->partial('common/left_menu.phtml'); ?>

Categories