I am getting a syntax error using blade templating...
<title>
#section('title')
this is my title
#show
</title>
The generated output fails to close the opening PHP tag?
<title>
<?php $__env->startSection('title')
this is my title
<?php echo $__env->yieldSection(); ?>
</title>
If i do the following it works as expected...
<title>
#section('title'); ?>
this is my title
#show
</title>
Any ideas?
Thanks.
try changing your code as follows,
<title>
#section('title')
this is my title
#stop
</title>
Notice: I have changed #show to #stop inside your code.
It looks like an EOL conversion problem.
If you are using Notepad++ on Windows be sure that you have 'Edit/EOL Conversion/Windows Format'.
Related
This may seem like an odd question, but I am new to Laravel and have a lot of trouble finding the right syntax in the official documentation. Here is an example. I was using the following blade syntax to try and have a conditional view:
#if (condition)
#extends 'layouts.regular'
#else
#extends 'layouts.special'
#endif
This did not work. I then went to the blade documentation on the Laravel site and read through the Extending a Layout section. All seemed well and I spent 10 minutes debugging my code and trying to find out if I did something wrong. It all seemed correct, so I then resorted to Google and found this thread.
From the comments I understood that:
The #extends statement must be the first line in a blade template
You can only use a conditional extend by using a ternary expression
While this solved my problem, it took too long to find. I still can't figure out WHERE in the official documentation this is mentioned. Am I using the official documentation wrong? Is there other, more extensive documentation out there? I keep feeling that the online documentation is very brief and often does not explain important details on syntax or exceptions...
#extends always comes in the first line of blade, it is used to define the layout e.g.
Assume we have master.blade.php
<html>
<head>
</head>
<body>
#yield('content')
</body>
</html>
Then we have page.blade.php
#extends('master') // this one says this page will be placed in master.blade.php
#section('content') // find the line that says #yield('content') and replace it with...
<h1> Hello World </h1>
#stop
Now, if you have many layouts and you want to share the content with it, you can achieve that programatically away from blade.. take this example
Assume we have master.blade.php
<html>
<head>
<title>Master</title<
</head>
<body>
#yield('content')
</body>
</html>
and we have master2.blade.php
<html>
<head>
<title>Master 2</title>
</head>
<body>
#yield('content')
</body>
</html>
and we have page.blade.php
#section('content')
<h1>Hello World</h1>
#stop
// note that we have no #extends()
now in the controller we do something like this
if($cond)
{
$layout = view('master');
}
else
{
$layout = view('master2');
}
$page = view('page');
$layout->content = $page;
return $layout;
Note that we are using $layout->content because both layouts are yielding content in #yield('content')
This is what I have written in my view
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Laravel PHP Framework</title>
</head>
<body>
<div class="welcome">
{{Hi everyone}}
</div>
</body>
</html>
It outputs {{Hi everyone}}
why is it not working ?
First: The view file should be named with a ".blade.php" after it.
Second: The {{ $str }} blade command it's only a shortcut to <?php echo $str ?>. That been said, if you want to just print a string, you should put it between " or even ', as you would probably do with a regular echo statement. Something like echo "Hi everyone";.
That SHOULD work on your case! :D
The file needs to be renamed as filename.blade.php. Check if the file had been named as per the convention rules.
You should call it in your route or controller with return View::make("hello"); etc. Also #Its Aafrin described, your file needs to be renamed as filename.blade.php.
There are diffrent ways to print. However you are just missing quotes. I have listed other methods also...
1. {{'Hi every one'}}
2. <?php $str='hi every one' ?> {{$str}}
3. <?= 'Hi every one' ?>
I'm learning Laravel 3, but Blade template is not working. My code seems correct, but all it displays is #layout('master'). Pages source also contains this text only.
application\views\home\index.blade.php contents:
#layout('master')
#section('main')
{{ $greeting }}
#endsection
application\views\master.blade.php contents:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Hello world!</title>
</head>
<body>
<div id="container">
#yield('main')
</div>
</body>
</html>
and in routes.php:
Route::get('/, home', function()
{
$greeting = "Hello world";
return View::make('home.index')->with('greeting',$greeting);
});
What can cause blade not to work? I tried Laravel 4 also, and changed #layout to #extends, #endsection to #stop but same situation. I get only #extends('master').
Not sure...but I think its because you have a space at the top of your file....
#layout('master')
needs to be directly at the top of the file for it to work properly...
Else it just echoes #layout('master') as words to the page, if you know what Im trying to say :)
same on me in L4...
check your charset of your code editor! sometimes some hidden chars are at the beginning of the file.
i switched to "UTF-8 without BOM"
Just remove every space or EOL, CR, LF, Enter, \n (or whatever) before your code.
Same issue in Laravel 4, I followed the quick start the step where you create a view I leave a new line.
-New line here, and it brokes-
#extends('layout')
#section('content')
Users!
#stop
Again remove anything before #extends('layout') and it works for me!!
My website was working fine, when all of a sudden a slash appeared right after the body tag. I tried to find out what was wrong but I had no luck.
How to fix this?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Toucan | <?=$title?></title>
<?php $this->load->view('include/head'); ?>
</head>
<body>
<div id="container">
<?php $this->load->view('include/header'); ?>
<?= $slideshow ?>
<table id="main">
<tr>
<?php if ($sidebar):?>
<td width="150px"><div id="sidebar"><?= $sidebar ?></div></td>
<?php endif; ?>
<td><div id="content"><?= $content ?></div></td>
</tr>
</table>
<?php $this->load->view('include/footer'); ?>
</div>
</body>
</html>
You should take a look at the end of your controller to check if you have a PHP closing tag : ?>. And maybe something like / after it...
This is good practice to omit the PHP closing tag at the end of your scripts.
I just google your webpage (toucan-eng.com) and a slash is showing in the main webpage. The title tag should be inside the head tag and then you need to put the body tag. Hope this can help you
I have a few questions regarding the HTML Helper on the code igniter website.
http://codeigniter.com/user_guide/helpers/html_helper.html
It shows where you can echo out the doctype but then my thinking is you'd have to do the manual html code for like the head tag, body tag and title tag but it has the meta tag.
So what would be the point in doing this?
<?php echo doctype(); ?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<?php
echo meta('description', 'My Great site');
echo meta('Content-type', 'text/html; charset=utf-8', 'equiv');
?>
</head>
<body>
</body>
</html>
In a model pop those meta tags into an array and sent it to your view. Then use a foreach to output your meta tags, and wha-la many lines of meta turn into one line of php, and your meta tags can easily be edited in your model.