I am new to Laravel so my problem is that I am trying to add multiple script files to my blade.php page using this code:
{{
HTML::script('js/bootstrap.min.js');
HTML::script('js/Chart.js');
}}
without any results , am I doing anything wrong or misunderstood some concept, please specify the best way to achieve my goal
only first include is working, the second one is not including
Thanks
You can't have line breaks inside Blade tags (at least not in Laravel 3). What you need to do is to add {{ ... }} for every HTML:: you have.
{{ HTML::script('js/bootstrap.min.js'); }}
{{ HTML::script('js/Chart.js'); }}
Related
I'm trying to add a github author's reference system project to my project. I did everything but stuck on the last step. He gave me the code to get the reference link, but I don't know where or in which file to add it.
Here GitHub link: https://github.com/questocat/laravel-referral
step where i got stuck and don't know where to add;
$user = App\User::findOrFail(1);
{{ $user->getReferralLink() }}
I tried doing
<p>{{ $user->getReferralLink() }} </p>
on a sample page, but it didn't work. I would be glad if you help.
hi sorry for my language.
im using laravel 5.6 to create a simple article site.
i have a problem with show article comments as string. the problem is : laravel try to render php codes and the page give me some errors.
imagine a user wants to send his laravel code as comment to me:
(this is just an example)
#foreach($article->tags as $tag)
<a class="tags" href="/tags/{{ $tag->slug }}">{{ $tag->title }}</a>
#endforeach
if user send this codes as comment to me, my page not loading and give me errors
my code to show comments :
{!!$comment->body !!}
help me please . thank you
Replace {!!$comment->body !!} with {{$comment->body }}.
When you use {!! !!}}, the template engine tries to parse the contents within the braces. Use {{ }} so that the contents are displayed as it is escaping all html.
i found the problem :
problem is for laravel blade codes.
like: #foreach . #if . #auth and ....
i have to scape this codes with space :
# foreach . # if and ....
A couple of days ago, I decided to start using laravel for the next project, but I'm confused as I don't find the documentation very compelling and I'm still a laravel beginner .
So, I didn't find a solution for how to create a layout using PHP (and not built in blade templating engine).
How can I do that? What's the best way to organize layouts in a big project?
Thank you
There are many methodologies that deal with handling templates.
Here are few,
1. Using a regular include or require
You can include the header.php , sidebar.php and footer.php and as many files that you prefer for each sector(It depends on the size of the template)
2. Using a common file and having classes inside it
Include a single file and call the classes to render each area
like
class Head {
public function render($_page, $_data) {
extract($_data);
include($_page);
}
}
3. Use a Templating Engine
You shall prefer few templating engine like smart, raintpl etc., (I guess you don't prefer it ;) )
4. Acquiring by inc
You can include as suggested here
<html>
<head>
<title><?=$this->title</title>
</head>
<body>Hey <?=$this->name?></body>
</html>
And the php area would be
$view = new Template();
$view->title="Hello World app";
$view->properties['name'] = "Jude";
echo $view->render('hello.inc');
5. By having template segments in db
Believe me, I saw many good sites which stores the template in the database and it will be rendered each time. It might look like strange idea, but even i tried it for one of my project.
Conclusion :
But if i use Laravel, for sure i will prefer the Blading Tempalte Engine and I recommend you the same.
Update :
Few benefits of Using Blade Templates
1. Easy Setting of attributes
Set the attributes on the go
<title>App Name - #yield('title')</title>
2. Easy yielding
<body>
#section('sidebar')
This is the master sidebar.
#show
<div class="container">
#yield('content')
</div>
</body>
3. Simple echoing
Like this
Hello, {{ $name }}
4. Easy Condition
Like this
{{ isset($name) ? $name : 'Default' }}
5. Never Escape
Like this
Hello, {!! $name !!}.
6. Beautiful If Statements
I prefer this way to make my code more beautiful
#if (count($records) === 1)
I have one record!
#elseif (count($records) > 1)
I have multiple records!
#else
I don't have any records!
#endif
7. Checking Authentication
The simplest way to check the authentication
#unless (Auth::check())
You are not signed in.
#endunless
8. Easy For Loop
How this for loop looks like
#for ($i = 0; $i < 10; $i++)
The current value is {{ $i }}
#endfor
9. Awesome foreach statement
Splitting the key and value can't be more easy than this
#foreach ($users as $user)
<p>This is user {{ $user->id }}</p>
#endforeach
10. Include the files
How about include file like this
#include('view.name')
11. Passing parameters to views
Can Pass this array to your view
#include('view.name', ['some' => 'data'])
Source : Laravel Templates
I stumbled upon this problem. I am using twitter bootstrap. I generate form elements like this:
{{ Form::button('Save', array('class'=>'btn btn-success')) }}
This is alright. But when I want to put an icon before the 'Save' like this,
{{ Form::button('<i class="icon-ok"></i> Save', array('class'=>;'btn btn-success')) }}
The <i> tag is not interpreted as it should be.Is there any workaround on this? How do I do this?
Any Body Give Some Idea
Thanks in advance.
You can use the HTML::decode method to wrap your button.
Example:
{{ HTML::decode(Form::button('<i class="icon-ok"></i> Save', array('class'=>;'btn btn-success'))) }}
HTML::decode converts entities to HTML characters according to laravel's api, found here:
laravel api
What version of Laravel are you using?
In Laravel 5, Blade has changed so that {{ }} is escaped by default (therefore not rendered as HTML by the browser) and you should use {!! !!} instead.
I am really new to Laravel as well as PHP.
I have some PHP code that I want to put it in Laravel.
But when I check the .blade files there are no PHP codes contained in them.
So, my question is: When can I put my PHP code in a Laravel application.
The PHP code relates to single.blade.
Thank you for your guidance.
Blade is the Laravel template, you should not put your code inside the blade file, it is not a good practice (not recommended), just things you are going to show on the final page.
You should put your code inside the controller.
So if you want to pass things to Blade you should do like:
View::make('single', array('var1' => $var1, 'var2' => $var2));
Everything between {{ }} is tranformed to an echo by Blade, so you can use any PHP code like this {{ date('d/m/y') }} on your Blade files.
So with this example above you should do {{ $var1 }} on your Blade file.
But with Blade you have flow control:
If-else:
#if ($var1 == $var2)
<p> equal </p>
#else
<p> not equal </p>
#endif
For-each:
#foreach($vars as $var)
<p>{{ $var }}</p>
#endforeach
For:
#for($i=0 ; $i<999 ; $i++)
<p>Number: {{ $i }}</p>
#endfor
While:
#while(isTrue($var))
<p>Loop forever</p>
#endwhile
Unless:
#unless(isRunning())
<p>keep</p>
#endunless
With this you can control what is printed on screen and you can use Laravel code like this (this code is adding an HTML class if the current route is equal to 'getFoo' to the element LI):
<li #if(URL::current() == URL::route('getFoo'))class="active"#endif>
This is a good start on how to use Blade. http://laravel.com/docs/templates