Blade is not working on laravel 4 - laravel-4

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' ?>

Related

Laravel Blade #yield is not working inside included view

I am trying to make layout using blade but the problem is that when i tried to
#yield on the file which is included in master file but #yield is not working.
resouces/views/layouts/app.blade.php
<html>
<head>
...
...
</head>
<body>
#include('layouts.navigation')
#include('layouts.main_panel')
#include('layouts.footer')
</body>
</html>
resouces/views/layouts/main_panel.blade.php
// some html stuff
#yield('form')
// some html stuff
resouces/views/auth/login.blade.php
#extends('layouts.app')
#section('form')
<form>
// input
</form>
#endsection
I would suggest you pass variables to the partials and echo
them inside it. This is an alternative way to achieve what you are
trying to do.
For example -
Partial blade file (resouces/views/partials.header.blade.php) -
<h4>{{ $name }}</h4>
View (resouces/views/custom.blade.php) -
#include('partials.header', [ 'name' => 'Lorem Ipsum' ])
I am also using laravel framework but i used to do in that way :-
Layout :- resouces/views/layouts/app.blade.php
<html>
<head>
...
...
</head>
<body>
#include('layouts.navigation')
#yield('content') // use #yield here why you need separate file
#include('layouts.footer')
</body>
</html>
After that :- resouces/views/auth/login.blade.php
#extends('layouts.app')
#section('content')
<form>
// input
</form>
#stop
Hope it helps!.. I used to follow this structure in laravel project

How to use official Laravel documentation?

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')

Laravel 3 blade template is not working

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!!

Blade Template Section Error

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'.

Using the HTML Helper For Code Igniter

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.

Resources