I am using laravel 5 and I have a blade templated page but {{}} doesn't work. It skips it and doesn't echo the value in it. For example. this code
<h2>Delete {{$employe->fname }} Are you sure?</h2>
Its output:
Delete are you sure?
with out the name of employee how can I fix this
the file is saved in blade extention delete.blade.php
Related
I am new to symfony.SO please find me a solution.On my controller
$table="<table><tr><th>Test</th></tr><tr><td>Show Test</td></tr></table>"
And I have Passed it to the twig from the controller like
return $this->render('lottery/transactions/trnissuenote/show.html.twig', array(
'table'=>$table
));
And on my twig
<div >
{{table}}
</div>
But i didnt get the table structure .Just echoing it.How will i get the table structure.Help me find a solution.
You need to display it using raw filter. Since by default {{}} escapes html content of a variable.
<div>
{{ table|raw }}
</div>
Read more: https://twig.symfony.com/doc/2.x/filters/raw.html
I want to show the result when search a keyword successful.
In routes\web.php:
Route::get('tim-kiem', 'Frontend\ListBaiVietController#timkiemBaiViet');
In controller ListBaiVietController, I have a function:
public function timkiemBaiViet() {
$tukhoa = \Request::get('tukhoa');
$ketquatimkiems = Post::where('title','like','%'.$tukhoa.'%')
->orderBy('title')
->paginate(20);
// var_dump($ketquatimkiems);
return view('post/searchresult',compact('ketquatimkiems'));
}
I am using var_dump($ketquatimkiems), it shows 2 results.
In post/index.php I am calling content:
<body>
#yield('content')
</body>
And post/searchresult.php:
#extends('post.index')
#section('content')
#foreach($ketquatimkiems as $ketqua)
<div class="container-artical">
<div class="list-excerpt">
{!! $ketqua->excerpt !!}
</div>
</div>
#endforeach
<nav class="blog-pag">
{{ $ketquatimkiems->links() }}
</nav>
</div>
#endsection
When I am typing text quận 8. It is only showing code, not result.
your file name must have .blade extension
post/searchresult.php: to post/searchresult.blade.php:
post/index.php to post/index.blade.php
for more information
Blade is the simple, yet powerful templating engine provided with Laravel. Unlike other popular PHP templating engines, Blade does not restrict you from using plain PHP code in your views. In fact, all Blade views are compiled into plain PHP code and cached until they are modified, meaning Blade adds essentially zero overhead to your application. Blade view files use the .blade.php file
Ref: https://laravel.com/docs/5.5/blade
you are not using laravel blade engine. Rename view
files like so index.blade.php
I am trying to create a button with the Form builder
{!! Form::button('<span style="color: {!! $colour[$i] !!}" class..') !!}
The rest of the contents of the button are irrelevant, what I was trying to do was make the colour of the font $colour[$id] which worked fine when I tested it in raw HTML, but it keeps exiting the quotes when I add blade inside another blade function.
I guess I can't do that, how would I be able to use php in blade code without exiting the function? Thank you in advance.
You should pass an array with your style to this method, like:
Form::button(['style' => 'yourstyle']);
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'); }}
I have been stumped for a couple days and I am seeking some direction.
I am attempting to call an image path stored in database to twig file in order to display said image. The twig example below, I am expecting the same image to be displayed twice. When inspecting the rendered html, the variable passes the path from the database, but the first image is not displayed.
From controller:
'logo' => $vendor->getLogovendors()
From database column logoVendors:
<img src={{asset('bundles/loginlogin/img/fs_logo_large.png')}} />
From twig:
<div class="container">
{{logo | raw}}
<img src={{asset('bundles/loginlogin/img/fs_logo_large.png')}} />
</div>
I am new to Symfony and its asset management. Any help or prodding in the right direction would be appreciated.
You should normally store only the path to the image in your database!
If logo was the variable you pass to the template holding the image path bundles/loginlogin/img/fs_logo_large.png you could simply include it using twig's asset function like this:
<img src="{{ asset(logo) }}"/>
what you're trying to do ( evaluating a twig function inside a string ) can be solved aswell...but i don't recommend it.
If you want to store the complete code including {{ asset() }} in your database you need to make twig evaluate the code inside the string.
This means twig shall execute the code inside the string instead of just printing it.
This can be achieved using the evaluate filter from this answer.
The final result would then be:
{{ logo |evaluate |raw }}