Questions tagged [laravel-blade]

Use this tag for questions about the Blade Template Engine, part of the PHP MVC framework Laravel

From the Laravel documentation:

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 extension and are typically stored in the resources/views directory.

7162 questions
600
votes
23 answers

How to create custom helper functions in Laravel

I would like to create helper functions to avoid repeating code between views in Laravel. For example: view.blade.php

Foo Formated text: {{ fooFormatText($text) }}

They're basically text formatting functions. How should I define globally…
Calebe Oliveira
  • 6,111
  • 3
  • 14
  • 7
413
votes
20 answers

Displaying HTML with Blade shows the HTML code

I have a string returned to one of my views, like this: $text = '

Lorem ipsum dolor

' I'm trying to display it with Blade: {{$text}} However, the output is a raw string instead of rendered HTML.…
lesssugar
  • 15,486
  • 18
  • 65
  • 115
343
votes
30 answers

How to Get the Current URL Inside @if Statement (Blade) in Laravel 4?

I am using Laravel 4. I would like to access the current URL inside an @if condition in a view using the Laravel's Blade templating engine but I don't know how to do it. I know that it can be done using something like
user2443854
  • 3,439
  • 2
  • 13
  • 3
338
votes
31 answers

How to Set Variables in a Laravel Blade Template

I'm reading the Laravel Blade documentation and I can't figure out how to assign variables inside a template for use later. I can't do {{ $old_section = "whatever" }} because that will echo "whatever" and I don't want that. I understand that I can…
duality_
  • 17,738
  • 23
  • 77
  • 95
162
votes
11 answers

How to comment code in a vue.js file?

I have the need to insert a comment inside a vue.js file for future references, but I don't find how you do this in the docs. I have tried //, /**/, {{-- --}}, and {# #}, but none of them seem to work. I am using Laravel's blade. So this is the…
Pathros
  • 10,042
  • 20
  • 90
  • 156
158
votes
14 answers

Laravel Pagination links not including other GET parameters

I am using Eloquent together with Laravel 4's Pagination class. Problem: When there are some GET parameters in the URL, eg: http://site.example/users?gender=female&body=hot, the pagination links produced only contain the page parameter and nothing…
Nyxynyx
  • 61,411
  • 155
  • 482
  • 830
154
votes
4 answers

Best Practices for Laravel 4 Helpers and Basic Functions?

I'm trying to understand the best place to put a global function in Laravel 4. For example, date formatting. I don't think making a facade is worth it as facades are too modular. I've read articles about creating a library folder and storing classes…
Jason Spick
  • 6,028
  • 13
  • 40
  • 59
123
votes
13 answers

Lumen: get URL parameter in a Blade view

I'm trying to get a url parameter from a view file. I have this url: http://locahost:8000/example?a=10 and a view file named example.blade.php. From the controller I can get the parameter a with $request->input('a'). Is there a way to get such…
Andrea
  • 15,900
  • 18
  • 65
  • 84
121
votes
15 answers

Truncate string in Laravel blade templates

Is there a truncate modifier for the blade templates in Laravel, pretty much like Smarty? I know I could just write out the actual php in the template but i'm looking for something a little nicer to write (let's not get into the whole PHP is a…
fl3x7
  • 3,723
  • 6
  • 26
  • 37
113
votes
12 answers

How do I pass a variable to the layout using Laravel' Blade templating?

In Laravel 4, my controller uses a Blade layout: class PagesController extends BaseController { protected $layout = 'layouts.master'; } The master layout has outputs the variable title and then displays a view: ... {{ $title…</div> <div class="grid ai-start jc-space-between fw-wrap"> <div class="grid gs4 fw-wrap tags "> <a href="../../questions/tagged/laravel" class="post-tag grid--cell" title="show questions tagged 'laravel'" rel="tag">laravel</a> <a href="../../questions/tagged/laravel-4" class="post-tag grid--cell" title="show questions tagged 'laravel-4'" rel="tag">laravel-4</a> <a href="../../questions/tagged/laravel-blade" class="post-tag grid--cell" title="show questions tagged 'laravel-blade'" rel="tag">laravel-blade</a> </div> <div class="started mt0"> <div class="s-user-card s-user-card"> <time class="s-user-card--time" datetime="asked Apr 20 '13 at 08:01">asked Apr 20 '13 at 08:01</time> <a href="../../users/1125910/dwight" class="s-avatar s-avatar__32 s-user-card--avatar"> <img class="s-avatar--image" src="../../users/profiles/1125910.webp" data-jdenticon-width="32" data-jdenticon-height="32" data-jdenticon-value="Dwight" /> </a> <div class="s-user-card--info"> <a href="../../users/1125910/dwight" class="s-user-card--link">Dwight</a> <ul class="s-user-card--awards"> <li class="s-user-card--rep" title="reputation score">12,120</li> <li class="s-award-bling s-award-bling__gold" title="6 gold badges">6</li> <li class="s-award-bling s-award-bling__silver" title="51 silver badges">51</li> <li class="s-award-bling s-award-bling__bronze" title="64 bronze badges">64</li> </ul> </div> </div> </div> </div> </div> </div> </div> <div class="mln24"> <div class="question-summary" id="question-summary-15232600"> <div class="statscontainer"> <div class="stats"> <div class="vote"> <div class="votes"> <span class="vote-count-post"><strong>105</strong></span> <div class="viewcount">votes</div> </div> </div> <div class="status answered-accepted"> <strong>19</strong> answers </div> </div> </div> <div class="summary"> <h3><a href="../../questions/15232600/laravel-stylesheets-and-javascript-don-t-load-for-non-base-routes" class="question-hyperlink">Laravel stylesheets and javascript don't load for non-base routes</a></h3> <div class="excerpt">Okay--I know this is a really elementary issue, but I can't figure it out. This is a question regarding Laravel. Basically, I have my stylesheets embedded in my default layout view. I'm currently just using regular css to link them, such as: <link…</div> <div class="grid ai-start jc-space-between fw-wrap"> <div class="grid gs4 fw-wrap tags "> <a href="../../questions/tagged/php" class="post-tag grid--cell" title="show questions tagged 'php'" rel="tag">php</a> <a href="../../questions/tagged/laravel" class="post-tag grid--cell" title="show questions tagged 'laravel'" rel="tag">laravel</a> <a href="../../questions/tagged/laravel-blade" class="post-tag grid--cell" title="show questions tagged 'laravel-blade'" rel="tag">laravel-blade</a> </div> <div class="started mt0"> <div class="s-user-card s-user-card"> <time class="s-user-card--time" datetime="asked Mar 05 '13 at 19:36">asked Mar 05 '13 at 19:36</time> <a href="../../users/1809762/pete" class="s-avatar s-avatar__32 s-user-card--avatar"> <img class="s-avatar--image" src="../../users/profiles/1809762.webp" data-jdenticon-width="32" data-jdenticon-height="32" data-jdenticon-value="Pete" /> </a> <div class="s-user-card--info"> <a href="../../users/1809762/pete" class="s-user-card--link">Pete</a> <ul class="s-user-card--awards"> <li class="s-user-card--rep" title="reputation score">7,289</li> <li class="s-award-bling s-award-bling__gold" title="10 gold badges">10</li> <li class="s-award-bling s-award-bling__silver" title="39 silver badges">39</li> <li class="s-award-bling s-award-bling__bronze" title="63 bronze badges">63</li> </ul> </div> </div> </div> </div> </div> </div> </div> <div class="mln24"> <div class="question-summary" id="question-summary-29739745"> <div class="statscontainer"> <div class="stats"> <div class="vote"> <div class="votes"> <span class="vote-count-post"><strong>103</strong></span> <div class="viewcount">votes</div> </div> </div> <div class="status answered-accepted"> <strong>3</strong> answers </div> </div> </div> <div class="summary"> <h3><a href="../../questions/29739745/laravel-blade-passing-variable-with-string-through-include-causes-error" class="question-hyperlink">Laravel Blade passing variable with string through @include causes error</a></h3> <div class="excerpt">In Laravel 5.0.27 I am including a view with with a variable and the following code: @include('layouts.article', [ 'mainTitle' => "404, page not found", 'mainContent' => "sorry, but the requested page does not exist :(" ]) and I…</div> <div class="grid ai-start jc-space-between fw-wrap"> <div class="grid gs4 fw-wrap tags "> <a href="../../questions/tagged/php" class="post-tag grid--cell" title="show questions tagged 'php'" rel="tag">php</a> <a href="../../questions/tagged/laravel" class="post-tag grid--cell" title="show questions tagged 'laravel'" rel="tag">laravel</a> <a href="../../questions/tagged/laravel-5" class="post-tag grid--cell" title="show questions tagged 'laravel-5'" rel="tag">laravel-5</a> <a href="../../questions/tagged/laravel-blade" class="post-tag grid--cell" title="show questions tagged 'laravel-blade'" rel="tag">laravel-blade</a> </div> <div class="started mt0"> <div class="s-user-card s-user-card"> <time class="s-user-card--time" datetime="asked Apr 20 '15 at 05:12">asked Apr 20 '15 at 05:12</time> <a href="../../users/1760315/joeyfb" class="s-avatar s-avatar__32 s-user-card--avatar"> <img class="s-avatar--image" src="../../users/profiles/1760315.webp" data-jdenticon-width="32" data-jdenticon-height="32" data-jdenticon-value="joeyfb" /> </a> <div class="s-user-card--info"> <a href="../../users/1760315/joeyfb" class="s-user-card--link">joeyfb</a> <ul class="s-user-card--awards"> <li class="s-user-card--rep" title="reputation score">3,044</li> <li class="s-award-bling s-award-bling__gold" title="3 gold badges">3</li> <li class="s-award-bling s-award-bling__silver" title="19 silver badges">19</li> <li class="s-award-bling s-award-bling__bronze" title="25 bronze badges">25</li> </ul> </div> </div> </div> </div> </div> </div> </div> <div class="mln24"> <div class="question-summary" id="question-summary-26732821"> <div class="statscontainer"> <div class="stats"> <div class="vote"> <div class="votes"> <span class="vote-count-post"><strong>100</strong></span> <div class="viewcount">votes</div> </div> </div> <div class="status answered-accepted"> <strong>15</strong> answers </div> </div> </div> <div class="summary"> <h3><a href="../../questions/26732821/displaying-the-error-messages-in-laravel-after-being-redirected-from-controlle" class="question-hyperlink">Displaying the Error Messages in Laravel after being Redirected from controller</a></h3> <div class="excerpt">How can I display the validation message in the view that is being redirected in Laravel ? Here is my function in a Controller public function registeruser() { $firstname = Input::get('firstname'); $lastname = Input::get('lastname'); …</div> <div class="grid ai-start jc-space-between fw-wrap"> <div class="grid gs4 fw-wrap tags "> <a href="../../questions/tagged/php" class="post-tag grid--cell" title="show questions tagged 'php'" rel="tag">php</a> <a href="../../questions/tagged/laravel" class="post-tag grid--cell" title="show questions tagged 'laravel'" rel="tag">laravel</a> <a href="../../questions/tagged/laravel-4" class="post-tag grid--cell" title="show questions tagged 'laravel-4'" rel="tag">laravel-4</a> <a href="../../questions/tagged/laravel-blade" class="post-tag grid--cell" title="show questions tagged 'laravel-blade'" rel="tag">laravel-blade</a> </div> <div class="started mt0"> <div class="s-user-card s-user-card"> <time class="s-user-card--time" datetime="asked Nov 04 '14 at 10:27">asked Nov 04 '14 at 10:27</time> <a href="../../users/4044949/sa" class="s-avatar s-avatar__32 s-user-card--avatar"> <img class="s-avatar--image" src="../../users/profiles/4044949.webp" data-jdenticon-width="32" data-jdenticon-height="32" data-jdenticon-value="SA__" /> </a> <div class="s-user-card--info"> <a href="../../users/4044949/sa" class="s-user-card--link">SA__</a> <ul class="s-user-card--awards"> <li class="s-user-card--rep" title="reputation score">1,782</li> <li class="s-award-bling s-award-bling__gold" title="3 gold badges">3</li> <li class="s-award-bling s-award-bling__silver" title="20 silver badges">20</li> <li class="s-award-bling s-award-bling__bronze" title="41 bronze badges">41</li> </ul> </div> </div> </div> </div> </div> </div> </div> <div class="mln24"> <div class="question-summary" id="question-summary-29897508"> <div class="statscontainer"> <div class="stats"> <div class="vote"> <div class="votes"> <span class="vote-count-post"><strong>97</strong></span> <div class="viewcount">votes</div> </div> </div> <div class="status answered-accepted"> <strong>9</strong> answers </div> </div> </div> <div class="summary"> <h3><a href="../../questions/29897508/switch-in-laravel-5-blade" class="question-hyperlink">Switch in Laravel 5 - Blade</a></h3> <div class="excerpt">How can I use switch in blade templates? When I used: @switch($login_error) @case(1) `E-mail` input is empty! @break @case(2) `Password` input is empty! @break @endswitch in result I see this text as…</div> <div class="grid ai-start jc-space-between fw-wrap"> <div class="grid gs4 fw-wrap tags "> <a href="../../questions/tagged/php" class="post-tag grid--cell" title="show questions tagged 'php'" rel="tag">php</a> <a href="../../questions/tagged/laravel" class="post-tag grid--cell" title="show questions tagged 'laravel'" rel="tag">laravel</a> <a href="../../questions/tagged/switch-statement" class="post-tag grid--cell" title="show questions tagged 'switch-statement'" rel="tag">switch-statement</a> <a href="../../questions/tagged/laravel-5" class="post-tag grid--cell" title="show questions tagged 'laravel-5'" rel="tag">laravel-5</a> <a href="../../questions/tagged/laravel-blade" class="post-tag grid--cell" title="show questions tagged 'laravel-blade'" rel="tag">laravel-blade</a> </div> <div class="started mt0"> <div class="s-user-card s-user-card"> <time class="s-user-card--time" datetime="asked Apr 27 '15 at 13:42">asked Apr 27 '15 at 13:42</time> <a href="../../users/3936476/ventaquil" class="s-avatar s-avatar__32 s-user-card--avatar"> <img class="s-avatar--image" src="../../users/profiles/3936476.webp" data-jdenticon-width="32" data-jdenticon-height="32" data-jdenticon-value="ventaquil" /> </a> <div class="s-user-card--info"> <a href="../../users/3936476/ventaquil" class="s-user-card--link">ventaquil</a> <ul class="s-user-card--awards"> <li class="s-user-card--rep" title="reputation score">2,780</li> <li class="s-award-bling s-award-bling__gold" title="3 gold badges">3</li> <li class="s-award-bling s-award-bling__silver" title="23 silver badges">23</li> <li class="s-award-bling s-award-bling__bronze" title="48 bronze badges">48</li> </ul> </div> </div> </div> </div> </div> </div> </div> <div class="mln24"> <div class="question-summary" id="question-summary-39508963"> <div class="statscontainer"> <div class="stats"> <div class="vote"> <div class="votes"> <span class="vote-count-post"><strong>96</strong></span> <div class="viewcount">votes</div> </div> </div> <div class="status answered-accepted"> <strong>6</strong> answers </div> </div> </div> <div class="summary"> <h3><a href="../../questions/39508963/calculate-difference-between-two-dates-using-carbon-and-blade" class="question-hyperlink">Calculate difference between two dates using Carbon and Blade</a></h3> <div class="excerpt">Does anyone know how to pass a given variable instead the Carbon's default parameters ? The documentation of Carbon says: // CARBON SAMPLE $dtToronto = Carbon::createFromDate(2012, 1, 1, 'America/Toronto'); $dtVancouver =…</div> <div class="grid ai-start jc-space-between fw-wrap"> <div class="grid gs4 fw-wrap tags "> <a href="../../questions/tagged/php" class="post-tag grid--cell" title="show questions tagged 'php'" rel="tag">php</a> <a href="../../questions/tagged/laravel" class="post-tag grid--cell" title="show questions tagged 'laravel'" rel="tag">laravel</a> <a href="../../questions/tagged/laravel-blade" class="post-tag grid--cell" title="show questions tagged 'laravel-blade'" rel="tag">laravel-blade</a> <a href="../../questions/tagged/php-carbon" class="post-tag grid--cell" title="show questions tagged 'php-carbon'" rel="tag">php-carbon</a> </div> <div class="started mt0"> <div class="s-user-card s-user-card__deleted"> <time class="s-user-card--time" datetime="asked Sep 15 '16 at 10:37">asked Sep 15 '16 at 10:37</time> <div class="s-avatar s-avatar__32 s-user-card--avatar"> </div> <div class="s-user-card--info">user5120193</div> </div> </div> </div> </div> </div> </div> <div class="s-pagination pager fr"> <div class="s-pagination--item is-selected">1</div> <a class="s-pagination--item" href="../../questions/tagged/laravel-blade_page=2" rel="" title="Go to page 2">2</a> <a class="s-pagination--item" href="../../questions/tagged/laravel-blade_page=3" rel="" title="Go to page 3">3</a> <div class="s-pagination--item s-pagination--item__clear">…</div> <a class="s-pagination--item" href="../../questions/tagged/laravel-blade_page=99" rel="" title="Go to page 99">99</a> <a class="s-pagination--item" href="../../questions/tagged/laravel-blade_page=100" rel="" title="Go to page 100">100</a> <a class="s-pagination--item" href="../../questions/tagged/laravel-blade_page=2" rel="next" title="Go to page 2"> Next</a> </div> </div> </div> </div> </div> <script src="../../static/js/stack-icons.js"></script> <script src="../../static/js/fromnow.js"></script> </body> </html>