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.
Related
I have a php page. The code is:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<meta name="viewport" content="width=device-width">
<?php include("some_file.php"); ?>
<title>Calculadora dos Custos do Automóvel</title>
</head>
<body>
<p>aaa</p>
</body>
</html>
As you can see nothing is wrong.
Though, view source of Firefox gives red erros and w3 validator gives also errors.
I'm around this for two days, and it is so strange. I suppose it has to do with some strange characters php might be inputting into the HTML code but I'm not sure. Or perhaps the encoding considering that the code has Portuguese characters.
There are two BOMs just before the <title> tag. Remove them (e.g. delete everything between the second <meta> and the <title>) and everything should work fine.
From what I see here you are using Notepad++ and we already cleared that the problem is because of BOM of the php files that you include before title.
To solve this for each file that you use open in Notepad++ and from menu choose Encoding -> Encode in UTF-8 without BOM and save the file. Do this for all your files in the probject (php files).
You should not have anymore that special characters in front of title.
Also make sure you start the <?php tag at the beginning of the file (no white spaces or new lines before) and if the file contains only php you don't have to use closing ?> tag. This way you are sure that you will not have spaces at the end of the file.
As others have said BOMs are a problem when including PHP files, even if those files do not echo anything
PHP includes
At the time this article was written, if you include some external
file in a page using PHP and that file starts with a BOM, it may
create blank lines.
This is because the BOM is not stripped before inclusion into the
page, and acts like a character occupying a line of text.
You should ensure that the included files do not start with a BOM.
in: http://www.w3.org/International/questions/qa-byte-order-mark
Detecting BOMs
You can online detect BOMs within the content of your HTML page using the W3C Internationalization Checker
There is something before
<title>
remove everything before title tag
try to save your file with UTF-8 encoding
You certainly have a problem with the white space before in your tag. Please rewrite your code afresh using your replacing the spaces with spaces from your keyboard.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<meta name="viewport" content="width=device-width">
<title>Calculadora dos Custos do Automóvel</title>
</head>
<body>
<p>aaa</p>
</body>
</html>
When my page is loaded from the server, source code differs from inspect element by changing the tags positions.
Here how the code looks in the view-source page
<!DOCTYPE html>
<html dir="rtl">
<head>
<link rel="stylesheet" type="text/css" href="css/mainclasses.css">
<title>title </title>
</head>
<body style="margin:0px;">
<div id="wrapper" style="margin:0px auto;">
but when I inspect elements all the tags inside the head tag goes under the body tag, and two double quotations appear under the body tag.
<!DOCTYPE html>
<html dir="rtl">
<head></head>
<body style="margin:0px;">
""
<link rel="stylesheet" type="text/css" href="css/mainclasses.css">
<title>title </title>
<div id="wrapper" style="margin:0px auto;">
The page works perfectly and all css properties appears and the title also appears.But I also want the HTML code to be good.
I searched for this and found many things that may cause this problem and none of them helped me.
There is no JavaScript code in my website, and I disabled all browser extensions so that JavaScript don't affect the page.I also checked the source tab in the developer tool and no JavaScript code were there.
I checked all my css properties and none of them causes this problem.(css also doesn't put strange chars).
The quotations that appeared are not spaces. I tried to put all my php code in one line and remove all unnecessary spaces and it didn't work.
I'm not using UTF8 BOM encoding, all files are UTF8 without BOM.so the strange chars are not due to file encoding.
I'm sure that the php files print the tags in the right order and don't print any quotation mark.
When I right-click the quotation marks in the developer tool,I only have the option Break on, and I can't edit it as HTML.
I tried to run the page from other web browsers and the problem didn't go.
I'm not using any framework.
What would be the cause of this problem, and how can I solve it?
I solved my problem.
I checked my HTML code. there were a symbol somewhere inside the head tag. I deleted the symbol and the HTML code in developer tool was corrected.
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.
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.
I don't know why every time I try to include my header using PHP’s include there's a top margin. I checked it using Firebug and it says there's a 22px offset margin on the top. Is anybody experiencing this problem? I think it's a CSS propiety: top: 22px. But nothing can change it even if I write h1 style="top: 0px; margin-top: 0px;". I think it's a php-CSS mystery that will never be solved.
edit: The only way to get rid of that top margin offset or whatever it is, is to add the follow properties to the H1: top: 0px;
position: absolute;
Will those properties generate more problems in the future?
is there a better way to solve this top margin-offset problem?
edit2: I think there's a problem with the encoding. Is there a conflict between the encoding of the included file (header.html) and the index file?
My index goes like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
<link rel="stylesheet" type="text/css" href="style2.css" />
</head>
<body>
<div id="page-wrap">
<?php include_once("header2.html"); ?>
</div>
</body>
</html>
With this CSS:
* {
padding: 0px;
margin: 0px;
}
My header.html (the one that’s being included):
<h1>Header 2</h1>
And that’s the output:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
<link rel="stylesheet" type="text/css" href="style2.css" />
</head>
<body>
<div id="page-wrap">
<h1>Header 2</h1> </div>
</body>
</html>
God its so simple that I really dont know where the top margin is coming from (in all browsers).
It only happens when I use php includes.
The source code looks the same as when I dont use php include.
This is pretty weird, but I copied & pasted your output HTML into Notepad++, and there was a strange character just prior to the h1. When pasting it into Notepad, the h in the h1 was subscripted.
Therefore, it looks to me like you may have an erroneous (or unexpected for PHP) character in your included HTML (or in the PHP including it). My suspicion? The dreaded UTF-8 BOM. Try to change the encoding of your included HTML file to eliminate the BOM (which I've always had problems with when dealing with PHP).
Edit: Yep. Just verified with a hex editor. There's a byte-order mark at the beginning of your included HTML. I don't know which editor you use, but you should have the option to change your text encoding settings.
See this for more info about PHP & the BOM.
You ought to post your generated HTML, like by copying what you see when you select "View Source" from your web browser. Oftentimes, I've seen mysterious blank lines in PHP-generated HTML because PHP is configured to output errors and warnings. Even if this is not caused by that, we can more-easily diagnose the problem if we see the outputted HTML.
I experienced the same problem...so what I did to fix it was to add an html opening comment at the beggining of the first file and an html closing comment at the beginning of the second file. This encloses the BOM (or whatever is appearing in between the files) inside a comment so it's not outputted in html.
For example:
#header.php
<?php ?>
<html>
<!--
#body.php
<?php ?>
-->
<body>
...
I tried to fix the problem converting between encoding formats in notepad++ to no avail. So this is only a temporary fix til I find a better solution to the problem.
well, without knowing what's in your php include, it's hard to tell, but make sure there's no CSS inside of it. also make sure that CSS you're loading is getting found and loaded. i debug by changing the background color or something else visual so u can be sure it's loading.
i'd bet anything that it has nothing to do with the php include it's self. like previously mentioned, there may be some css in the included file that is doing it, but i've never seen php anything like what you are describing.
i would look at the doctype declaration [temporarily remove it to see what happens], and remove the current html declaration tag and replace it with a plain <html> tag [again just temporarily, to debug]
A lot of times an extra new line will be at the end of a PHP script file you are including after the ?> tag. This will cause an extra character to be included in the generated output. You can remedy this problem by not having a closing ?> tag at the very end of your file. PHP knows to "assume" that it's closed.
Do you have the option to give us a link? I just tried locally a couple of things and you may get this "unwanted" new line for apparently "no reason" at all between your content and the "doctype" declaration, if there is a nonprintable character. Try to delete all characters after the ">" and take a look at it with a hexeditor to make certain of it. Please provide us more info.
Thats very interesting, because I just used your markup and your css. I also put it into an php file and included a html file. But there is no margin. Nowhere.
So make sure your browser is able to find the css file with
* { margin: 0; padding: 0 }
And I suggest you to use a reset sheet like this one - http://meyerweb.com/eric/tools/css/reset/index.html.
p.s. if you own some webspace, put it online and send us a link.
Dreamweaver drives me nuts with it's automatic BOM additions. Here's the fix:
http://www.adobe.com/support/documentation/en/dreamweaver/mx2004/dwusing_errata/dwusing_errata2.html
I am using notepad and I selected from the menu -> Encoding->Encoding with UTF-8 without BOM and it worked just fine. This should be done for every included file. I think this is the solution to your problem. Have a nice evening.
I almost killed my keyobard trying to solve to problem.
Then I tried PSPad editor, change explicitly .inc or .php to UTF-8 and IT WORKED !!
I had one time this problem and here is the way to fix it - its really problem in charset.I have spent 10 hours to find it. In my situation I change at all php files(all php files, all tpl(if you have) files) charset from UTF-8 to UTF-8 without bom and save it and try then. After that you can also make at .htaccess string "AddDefaultCharset UTF-8".