Laravel 4 Blade BUG - php

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.

Related

My HTML elements embedded in Laravel PHP file aren't displayed properly when running on XAMPP Apache server

I've been trying to turn my HTML project into PHP one while learning Laravel. However, when embedding codes in old HTML files into my new PHP files in Laravel and running them on XAMPP Apache server, it shows only plain HTML texts without images, buttons and audio.
Here are my codes:
<?php
echo('<DOCTYPE html>
<head>
<title>Epsilon Program</title>
<link rel="stylesheet" href="main-settings.css"/>
<meta name="epsilonprogram" charset="UTF-8" lang="en">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<audio autoplay id="mainaudio">
<source src="resources/views/Assets/kifflom_music.mp3">
</audio>
<script>
var audio = document.getElementById("mainaudio");
audio.volume = 0.1;
</script>
<div class="container" style="height: auto;">
<div class="upper">
<div class="content">
Meet Cris Formage<br>
Celebrities<br>
House of Worship<br>
Meet Members<br>
Beliefs and Practices<br>
Unsaveables<br>
</div>
</div>
<div class="introduction">
<h2 class="greet" style="color: #456483"> Welcome to The Epsilon Program</h2>
<p2 name="greet1" style="color: #779BBB"> Do you want to be shappy and free from thought, or continue dying in ignorance without knowing your true eternal self? You are controlled by lots of powerful forces you do not understand.</p2> <br>
<br>
<p2 name="greet2" style="color: #779BBB"> Do you want to believe? Are you everything you need and less and more? Then you are ready. </p2> <br>
<br>
<p2 name="greet3" style="color: #779BBB"> Do you want to be rich in powerful tools? Our time has come, so has yours, if you let in. </p2> <br>
<br>
<p2 name="greet4" style="color: #779BBB"> The tract is now being written. </p2> <br>
<div class="evaluatebutton">
EVALUATE YOUR IDENTITY
</div>
<div class="donationbutton">
Make a Donation
</div>
</div>
</div>
</body>
</DOCTYPE>')
?>
It should look like this:
instead of this:
By the way, it doesn't even change the content of page when I click the button to navigate to another page. For instance:
Meet Cris Formage<br>
Please help!
Looks like the style sheet don't get importet. You can make after your </head> a <style></style> tag and put your main-settings.css code there
When you use laravel framework for web development, you should add your html codes in blade.php files (inside of the resources folder -> views). In here, stylesheet is not linked properly. Make sure that you have added the CSS file correctly and if the matter still remains, try this option below ->
<scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
add above 2 links inside the tag.
Try to refer some Youtube tutorials about laravel framework.
Best of luck :)

CSS doesn't apply to an included PHP file

I want to separate my code to make it clearer. To do so, instead of having one big php file I spare them and keep one "main" file where I include the others when I need. The problem is that CSS only apply to the "main" file, but not to included files.
I'm pretty sure this is not a path issue, for I'm working with every files in the same folder (I know it's not the best way to work, but so far I only have few files so it's not a big deal). I have double checked eventual writing mistakes.
Here is my "main" php file :
<!DOCTYPE html>
<html>
<head>
<title>A very nice title</title>
<link rel="stylesheet" type="text/css" href="style1.css">
<meta charset="utf-8" />
</head>
<body>
<?php include("file2.php"); ?>
</body>
and here is my "file2.php" file :
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style1.css">
<meta charset="utf-8" />
</head>
<div class="beer">
<img src="simple_beer.png" alt="beer picture"/>
<div class="description>
<p> a simple text </p>
<form id="add" action="[nothing interesting]">
<input type="number>
<input type="submit" value="add to card">
</form>
</div>
</div>
So i'm using the same CSS files for both php files. But it's not working on the file2.php when I have a look at it (I'm working on a local host). I've tried to delete cache from my browser (firefox). If you're wondering why I'm working on php files instead of HTML, it's simply because I intend to add php code later.
I have been looking for a solution for almost two hours, nothing seems to work. Thanks in advance !
Include everything header-related inside main.php file, remove head section from file2.php and then include file2.php in the body section of main.php. When you include that file, it will get everything that is above. That means whatever you have in main.php before include() function, will be accessible in called file (thanks to that you can link everything once and have it available in all called files).
Include() brings full code structure from the called file which you do not need (talking about head tag) if main file will hold everything that you need inside tag.

Laravel Blade rendering <head> contents inside <body>

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.

laravel blade include error - syntax error, unexpected

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.

Random whitespace in a PHP page (the client received page, but not the client-received source-code), but only when I use an include()

Ok, I am having the weirdest problem in history. I am making a website that works perfectly in HTML, but is having some REALLY odd behaviour when rendered from PHP - despite having the EXACT SAME client source code (I literally went through it character by character).
At first I thought I'd messed up something in my 'functions.php' file that I'm including, but I don't get any errors, and when I copy&paste the contents of that file into the place where the include('functions.php'); line is, the problem disappears.
Here's my code (with some HTML removed, this is all of the PHP):
<?php
error_reporting(E_ALL);
ini_set('display_errors','1');
include 'functions.php';
$footer = file_get_contents('footer.txt');
?>
<!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 http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Removed</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.1/jquery-ui.min.js"></script>
<script type="text/javascript" src="js/main.js"></script>
<link type="text/css" rel="stylesheet" href="css/jquery-ui-custom.css" />
<link type="text/css" rel="stylesheet" href="css/main.css" />
</head>
<body>
<div id="header">
<div id="headerContent">
<div id="logo">
</div>
<?php
echo trim(GetNav());
?>
</div>
</div>
<div id="content">
<?php
$NumberOfNewsItems = 2;
echo trim(GetNews($NumberOfNewsItems));
?>
</div>
<?php
echo trim($footer);
?>
</body>
</html>
The functions GetNav and GetNews grab info from the database so I'm not going to show the code from them, plus, as I mentioned earlier, if I don't include the file but instead copy it's contents to the place I make the include call then most of the whitespace disappears (there's still some where the 'echo $footer' call is.
Basically, when you look at the source code, everything looks fine. Where stuff gets incredibly strange is when you hit F12 to look at the dev tools and the elements tab shows a whole bunch of extra whitespace (surrounded by double quotes) immediately after the tag (which impacts the look of the site) as well as between the footer and content Divs (which again, impacts the look of the site).
Also in this view, all of the tags from the are below the first set of white-space and the tag is empty (eg: <head></head>).
The source code looks fine (and if I copy and paste the source code into a HTML file it works flawlessly) and I have to admit that this has me tearing my hair out.
Please help me Obi-Wan-Kenobi, you're my only hope (yes, I love Star Wars, although I wish they'd made more than three movies).
P.S. This might be mega-obvious, but I'm a .Net developer doing this for a family member in my spare time (also it's fun to learn new languages, even ones overly fond of the $ sign), so apologies in advance if I'm the world's biggest newb.
EDIT: What I see in the dev tools is this:
<html xmlns="http://www.w3.org/1999/xhtml">
<head></head>
<body>
"
"
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Removed</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.1/jquery-ui.min.js"></script>
<script type="text/javascript" src="js/main.js"></script>
<link type="text/css" rel="stylesheet" href="css/jquery-ui-custom.css" />
<link type="text/css" rel="stylesheet" href="css/main.css" />
Etc.
EDIT2: Just to be clear, I don't care what the dev tools show, it's just that I'm getting whitespace showing where those quotes are on the actual website, other than that everything is perfect.
EDIT3: Also, the whitespace cannot be clicked on with the element selector and selecting the whitespace in the element tab does not highlight anything on the website. Deleting it in the element tab however DOES fix the website (until it is reloaded obviously), but obviously doesn't help me with my problem.
Try removing the ?> in your functions.php file and no blank rows after the code. And is the functions.php in the same directory as the main file?
And just a tip, include a footer.php instead of file_get_content :-)
I wasn't able to fix this in a way that satisfies me, but here's the workaround that I implemented:
I removed the include from the header entirely and broke up functions.php into one file per function and just included them where they needed to be called.
This alleviated my problem, although it's not ideal. Glad I don't have to use PHP on a daily basis :).
I had the same issue, on the console the source of the html looked like :
By checking the encoding some files were encoded with utf-8 with bom and some with big5. By saving those file to utf-8 ( without bom) solved the issue for me.
I have used Sublime Text 2 with the EncodingHelper from the package manager to see the current file encoding.
Hope it helps.

Categories