I'm using Laravel 4 locally with EasyPHP 14.1.
I have created a route :
Route::get('/test', function()
{
return View::make('test');
});
a layout (testlayout.blade.php) :
<!doctype html>
<html>
<head>
<title></title>
</head>
<body>
<div class="container">
#yield('container')
</div>
</body>
</html>
and a view (test.blade.php) :
#extends("testlayout")
#section('container')
<h1>Hello!</h1>
#stop
It works fine and I get "Hello!"
But when a change my layout by adding an include like this :
<!doctype html>
<html>
<head>
<title></title>
</head>
<body>
<div class="container">
#yield('container')
</div>
#include('testfooter')
</body>
</html>
with my footer (testfooter.blade.php) :
#section("testfooter")
<div class="footer">2013-2014</div>
#show
I have an error "syntax error, unexpected '/'".
The code generated by Laravel (found in app\storage\views) is wrong :
<!doctype html>
<html>
<head>
<title></title>
</head>
<body>
<div class="container">
<?php echo $__env->yieldContent('container')
</div>
<?php echo $__env->make('testfooter', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>; ?>
</body>
</html>
Laravel forgets ;?> after yieldContent('container') and adds two ;?> after ... render().
I've tried many things but I really don't have any clue now.
UPDATE1
I have reinstalled a fresh Laravel and guest what, the problem is still the same. Without #include it's ok, with an #include I have the same error again and again.
UPDATE2 and PROBLEM FIXED (thanks to #majimboo)!
This is just unbelievable. All that story is not related to the code. This is a problem with the text editor : Notepad++ on Windows. For an unknown reason, and for somes files only, it switched from 'edit/EOL conversion/windows format' to 'edit/EOL conversion/Mac format'. And apparently, Laravel doesn't Mac format at all! So, if you use Notepad++ on Windows, be sure that you have : 'EOL conversion/windows format'
the problem is in the file that is getting included.
First to check if the problem is really that, remove everything inside testfooter.blade.php then open the view from the browser. You'll notice that there is no error anymore.
Change your testfooter.blade.php to:
<div class="footer">2013-2014</div>
remove the #section("testfooter")...#show.
Example:
<!-- app/views/header.blade.php -->
<h1>When does the Narwhal bacon?</h1>
<!-- app/views/footer.blade.php -->
<small>Information provided based on research as of 3rd May '13.</small>
You include it like:
<!-- app/views/example.blade.php -->
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Narwhals</title>
</head>
<body>
#include('header')
<p>Why, the Narhwal surely bacons at midnight, my good sir!</p>
#include('footer')
</body>
</html>
Check this to learn more on blade.
The problem seems to be something else, I would just like to share this, If it can help you:
I'm using Notepad++ as text-editor and for some strange reason it had
decided to use "MAC format" as the End-Of-Line (EOL) format.
Apparently the Blade framework can't cope with that. Use the
conversion function (in notepad++ : Edit -> EOL Conversion) to convert
to Windows Format and it will work just fine...
Arjen
You have this:
#section("testfooter")
<div class="footer">2013-2014</div>
#show // <--
Change it to this:
#section("testfooter")
<div class="footer">2013-2014</div>
#stop // <--
In my case the issue was an unterminated string in some PHP in a totally different part of the file than Laravel was complaining about. I eliminated it by removing everything in the file and adding the lines in again one by one.
Usually Laravel gives a great hint to the problem. The problem might be in your CSS or JS include statements. First make sure you have turn on the debug mode of laravel. Here is how to do it.
Config/app -> debug = true at line 16
Refresh the page where the error is
I have intentionally leave out closing ')' of css file. The laravel FW showed where that error, and it will show you similar error.
Hope it help.
Related
I'm using NetBeans 8.2 and I want it to highlight bad HTML syntax in a .php file. For example:
<!DOCTYPE html>
<html>
<head
<meta charset="UTF-8">
<title> </title>
</head>
<body>
<?php
echo "hi";
?>
</body>
</html>
The above is missing the > character on the <head> tag. In a .html file, NetBeans would flag this. But it does not flag it in a .php file. Any help would be much appreciated.
Sam.
For me it is working, after some seconds of waiting. Using NetBeans 8.2 Patch 2
I figured it out. Click the lightbulb in the top left of the editor window when looking at a PHP Web Page, and there's an option to add HTML syntax checking. I guess it's just turned off by default.
For the past couple of days I have been trying to get into Laravel 5 blade system. Yet for some absurd reason I cannot get things to work. Here's how things look now:
UserController -> index
public function index()
{
return view('app');
}
So obviously we are getting a view so I create a blade file in views called app.blade.php
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
</body>
</html>
Alright so we are all set so when I load the page all I get is "Document" in the title.
Here's the rub: if I change the title tag to something else like so:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Application</title>
</head>
<body>
</body>
</html>
And reload the page one would expect to see the title change? Well guess what? Nope. That didn't happen. The original title "Document" is still there.
Someone want to tell me whats going on here and how to fix it?
Are you sure it's not just cached? Try this: go to your \storage\framework\views and delete everything except .gitignore file, and try again.
If laravel is caching your view, clearing the browser cache won't help you as the caching is done server-side.
If you are actually using laravel 5.1, you can type on your terminal php artisan view:clear
More info: laravel.com/docs/5.0/cache
I need a little help here...
When I try to render a simple template in blade, I get a bad rendered html.
I have master.blade.php and home.blade.php inside views.admin directory.
<!-- master.blade.php -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>Test Title</title>
</head>
<body>
Content
</body>
</html>
<!-- home.blade.php -->
#extends('admin.master')
The rendered HTML when I call return view("admin.home"); looks like this:
<html lang="en">
<head></head>
<body>
<meta charset="utf-8">
<title>Test Title</title>
Content
</body></html>
Any ideas of what is happening?
Thanks.
For me, this was caused by adding a ; to end of #extends('layouts.app')
I just spent about an hour trying to solve this, before deciding to make a new laravel app to paste new files over until it was fixed. It turns out my issue was because of a random character inserted into one of my config files (probably when trying to type in a url before realising my browser wasn't the active window). So if anyone can't seem to figure out why it isn't working after fixing their blade templates, check this.
Usually the case for the "" character appearing is that it has been introduced by using a non UTF-8 encoded text editor or was introduced in a different way. My suggestion would be to use something like Sublime Text or Notepad++ to create fresh versions of each of these three documents. This usually happens because of a copy/paste without realizing it or using a text editor that has "extra formatting" that you cannot see (e.g. Word). The character is ZERO WIDTH NO-BREAK SPACE (you can see more information here). So, it's not a Laravel Blade issue, it's that extra whitespace-type characters are being introduced by whichever text editor you're using.
I know the thread is old, but I faced this issue today and removing BOM helped me to fix it. One hint - if you are using PHPStorm, there is option to remove BOM, without need to copy the file and save it with another file editor. Just right click on the file and press "Remove BOM". Works like charm!
I know this is an old question, but for the sake of someone as me that had the same problem and came up to this page, I want to share what solved my problem.
As you may find in laravel's layout documents, it is stated that a master template should be used like this:
#extends('layouts.master')
#section('title', 'Page Title')
#section('sidebar')
##parent
<p>This is appended to the master sidebar.</p>
#stop
#section('content')
<p>This is my body content.</p>
#stop
My problem solved by adding #stop at the end of #section('content'). I hope this helps.
I'm working with PHP Fat Free and I am attempting to create a layout/sublayout system which will eventually mimic MVC to some extent. I have a main layout which has placeholders (essentially the backend sets different sublayout or partial file paths and then the view takes care of calling the rendering of that file name. This all works great.
The issue I'm running into is when I need inline javascript in my sublayout to run after scripts in the main layout (after the jquery include line, for instance). In a previous framework I was using, I was able to do us output buffering ob_start and ob_get_clean to grab the script in the sublayout and then pass that to the layout to display below the script line. I hope that makes sense, but if not, here's the current code I'm working with in F3.
The route:
$f3->route('GET /test',
function($f3) {
// set the sublayout name
$f3->set('sublayout', 'testpage.php');
// render the whole shebang
echo View::instance()->render('testlayout.php');
}
);
The layout:
<!DOCTYPE html>
<html>
<head>
<title>Test Layout</title>
</head>
<body>
<h1>Test Layout</h1>
<?php echo View::instance()->render($sublayout) ?>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js" />
<!-- inline script should go here -->
</body>
</html>
The sublayout:
<h2>My Test Page</h2>
<div id='message'></div>
<script>
// This code needs to be placed AFTER the jquery include in the main layout
$(function(){
$('#message').html('This is my message');
});
</script>
I tried extending the view to include a "beginRegion" and endRegion function that basically handled the ob_start and ob_get_clean portion so that my inline script could be picked up, but once I'm in the sublayout I wasn't able to figure out how to pass that buffered code back to the layout so it could be echo'd after the jquery include.
Before you tell me that I should not be using inline script, I know this and most things I do are in external script files which I have a solution for including, but there are times when I need it inline and that's where I'm stuck.
Is there a way to handle what I'm trying to do with output buffering, or better yet is there a better way to solve this than the output buffering approach?
Update:
Best practices generally dictate that you should include the script at the bottom of the page right before the closing body tag. If I put the script above the sublayout, it breaks both our FE best practices and has the disadvantage of blocking the rest of the page while the script downloads. That's why I'd like to keep it structured the way I have noted instead of placing the jquery include ABOVE the sublayout.
I don't understand what's the problem.
Your layout is:
<!DOCTYPE html>
<html>
<head>
<title>Test Layout</title>
</head>
<body>
<h1>Test Layout</h1>
<?php echo View::instance()->render($sublayout) ?>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js" />
<!-- inline script should go here -->
</body>
</html>
You want to include sublayout after jquery usage. So why not to write it like this? :
<!DOCTYPE html>
<html>
<head>
<title>Test Layout</title>
</head>
<body>
<h1>Test Layout</h1>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js" />
<!-- inline script should go here -->
<?php echo View::instance()->render($sublayout) ?>
</body>
</html>
Also You can write custom function. Lets say You've folder with partials or something else more structured and want to use it:
$f3->set('partial',
function($file) {
$file .= (strpos($file, '.php')>0)? '' : '.php';
if(!is_file($file)) return '';
return View::instance()->render($file);
}
);
and then use it like:
<!DOCTYPE html>
<html>
<head>
<title>Test Layout</title>
</head>
<body>
<h1>Test Layout</h1>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js" />
<!-- inline script should go here -->
{{ #partial('partials/testpage') }}
</body>
</html>
I knew why You want to do so. But what's the problem to decouple scripts in scripts.php file and HTML,php part to another file and render them as needed? (:
From a google groups discussion I had, someone offered up a JS solution that might work:
inside your layout:
<head>
<script>
var callbacks=[];
</script>
</head>
<body>
<script src="...jquery.min.js"/>
<script>
$.each(callbacks,function(i,func){func.call(null,jQuery);}) //<< triggers all queued callbacks
</script>
</body>
inside your sublayout:
<h2>My Test Page</h2>
<div id="message"></div>
<script>
callbacks.push(function($){
//do something with jQuery
});
</script>
Here's the link:
https://groups.google.com/forum/#!topic/f3-framework/iGcDuDueN8c
Having trouble getting blade template to work... all that is displayed on the page is:
#extends('layouts.admin')
Here is the route:
Route::get('login', function(){
return View::make('admin.login');
});
Here is the template: layouts/admin.blade.php
<!doctype html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
<meta name="viewport" content="width=device-width" />
</head>
<body>
<div class="large-12 columns">
<div id="wrap" class="large-8 large-centered columns">
#yield('content')
</div>
</div>
</body>
</html>
And here is the view: views/admin/login.blade.php (no breaks or space before #extends)
#extends('layouts.admin')
#section('content')
<h1>Admin Login</h1>
...
#stop
Any help appreciated!
I don't see any errors in your code, it works fine for me and more people here. So you might have problems in some other part of your code that you're not showing to us.
I just made this git repository reproducing the code you posted here.
It may prove to you that Laravel works and sometimes the problem is just elsewhere. Or it may prove to us that in some environments Laravel is broken, wich might help the project.
So, please, give it a try and tell us what you get going to the route http://your-host/login.
This wasted hours of my life. There was nothing in the code that was wrong and I would still possibly consider this a bug since no errors were generated. I finally ended up creating NEW files with the EXACT same code and replacing the existing blade files and suddenly it magically works. I'm not sure if somehow the files were corrupted or what but hopefully this will save somebody hours of frustration.
I've had the same exact problem. You are using UTF. UTF leaves a byte order mark or BOM at the beginning of the file and it's invisible to most text editors. Just download a BOM REMOVING SOFTWARE so that it will work.
cheers.