I am trying to include files in my homepage using blade syntax :-
#foreach($data as $articles)
#include(app_path().$articles->path)
<br />
#endforeach
This is not working.
The error says :-
View [/var/www/blogproject/project/app/pages/articles/first-post.php] not found
I even tried including just the first page :-
#include(app_path().'/pages/articles/first-post.php')
But the normal php include is working fine :-
<?php include(app_path().'/pages/articles/first-post.php'); ?>
Please help
That's because that file is not in the app/views directory. When you call #include('filename'), Blade automatically looks for any file with that name, inside the apps/views directory. Also, you're not supposed to write the file extension, as Blade automatically looks for files with .blade.php and .php extensions.
If you want to use files from other directories on the #include tag, add the directory to the paths array, on app/config/view.php. In your case, it'd be something like this:
app/config/view.php
<?php
// ...
'paths' => array(
__DIR__.'/../views',
__DIR__.'/../pages'
);
Then, you'd call it on blade like so:
#include('articles/first-post')
Related
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.
I cannot get laravel blade view to work, removing the blade from file name makes it work. I am using laravel 5.2.22.
Here are the details:
Here is the route:
Route::get('/', function () {
return view('login2');
});
Location and file name of 'login2': /resources/views/login2.blade.php
Inside of login2.blade.php:
<?php
echo "a";
As soon as I change the "login2.blade.php" -> "login2.php" it works.
Any ideas?
I changed rights for folder storage to 777 and now blade views work.
Try to close tag:
<?php echo "a"; ?>
Blade template files are parsed with a template engine, so you need to close tag if you're using raw PHP inside a template.
I have a project in laravel5 and I have directed virtual host on /public directory. Where should be my main page index.php now? There is some index.php in public folder already but it contains some content that I dont understand. So where should be my index now? Maybe in views?
If you are using Laravel 5.1 then your initial page should be this resources/views/welcome.blade.php.
You can change it to any name. But also you should change the same in your Controller.
Note : If you are rendering the view through controller then you should have the file name like this yourfilename.blade.php
Your views should always inside resources/views/*
The index file stays at the same place, to call a new file that you made, could be with HTML, you can put that file in the view and call it from the controller, hope this is the answer you are looking for.
When a request come to your server, the first file that it is executed is index.php. But this is not the file shown. In Laravel you don't have to force any file be named index.php. So let's imagine that you are trying set up a new index file. You have to use routes.php
routes.php
Route::get("/" , "HomeController#index");
HomeController.php
function index(){
return view("home/index");
}
views/home/index.blade.php
<html>
<head>
</head>
<body>
<p>Index page</p>
</body>
</html>
When a GET request to "/" it's done, the index function of the HomeController it's executed and the view index.blade.php, stored in views/home it's shown.
This it's the basic behaviour of Laravel. So you mustn't rename or move the index.php file in public folder.
I am trying to include files on my page whose paths are stored in my db. I have tried :-
#foreach($data as $articles)
#include( $articles->path )
<br />
#endforeach
This is not working. What am I doing wrong.
I have my files in a folder called pages in view and I have added .blade.php extension as well.
You need to make sure that the path you are referencing actually exists as a file in the views folder i.e.
application/views/pages/articles/first-post.blade.php
One thing I've seen a lot of people do is add views to the home folder but not added it to the include path e.g.
application/views/home/pages/articles/first-post.blade.php
Also, it looks like you are not calling the path correctly in #include. Should be using dot notation
#include('pages.articles.first-post);
You also need to make sure you aren't trying to get a view from a bundle. You need to append the bundle name if you are, like so.
#include('bundle_name::pages.articles.first-post');
I'm sure it's a simple one-liner, but I can't seem to find it.
How can I use a different layout file for a particular action?
Update: This worked for me, thanks!
// Within controller
$this->_helper->_layout->setLayout('other-layout') //other-layout.phtml
//Within view script
<?php $this->layout()->setLayout('other-layout'); ?>
From inside a Controller:
$this->_helper->layout->setLayout('/path/to/your/layout_script');
(via these docs)
EDIT: I should mention that the path is relative to whatever your layout directory is (by default, it's application/layouts/scripts/)
You can also use like this
// Within controller
Zend_Layout::getMvcInstance()->setLayout('layout_name');
//Within view script
<?php $this->layout()->setLayout('layout_name'); ?>
Your layout must be in /layouts/scripts/ folder, otherwise you need to specify the path also. No need to write .phtml, just name of the layout