blade

Laravel blade模板 @yield和@section

最后都变了- 提交于 2019-11-30 08:09:32
Laravel 框架中的 Blade 模板引擎,很好用,但是在官方文档中有关 Blade 的介绍并不详细,有些东西没有写出来,而有些则是没有说清楚。比如,使用中可能会遇到这样的问题: 1. @yield 和 @section 都可以预定义可替代的区块,这两者有什么区别呢? 2. @section 可以用 @show , @stop , @overwrite 以及 @append 来结束,这三者又有什么区别呢? 本文试对这些问题做一个比较浅显但是直观的介绍。 @yield 与 @section 首先, @yield 是不可扩展的 ,如果你要定义的部分没有默认内容让子模板扩展的,那么用 @yield($name, $default) 的形式会比较方便,如果你在子模板中并没有指定这个区块的内容,它就会显示默认内容,如果定义了,就会显示你定义的内容。非此即彼。 与之相比, @section 则既可以被替代,又可以被扩展 ,这是最大的区别。比如: 代码 如下: {{-- layout.master --}} @yield('title','默认标题') @section('content') 默认的内容 @show 代码如下: {{-- home.index --}} @extends('layout.master') @section('title') @parent 新的标题 @stop

what is laravel render() method for?

試著忘記壹切 提交于 2019-11-30 07:49:24
问题 I didn't deal with render method yet !! is it for blade template ? I have to pass dynamic data in blade.php file dynamically. 回答1: Given that you've tagged the question with Blade, I'll assume you mean render inside Laravel's View class. Illuminate\View\View::render() returns the string contents of the view. It is also used inside the class' __toString() method which allows you to echo a View object. // example.blade.php Hello, World! // SomeController.php $view = view('example'); echo $view-

Laravel 4 - Blade Templating - How to properly Link to Route?

六眼飞鱼酱① 提交于 2019-11-30 06:55:49
问题 I want to create a resourceful link with Laravel. Normally I just use the {{ link_to_route('Yadayadayada.route', 'LinkName', $params }} But in this case I am using a Template with this layout: <a href="index.html"> <i class="icon-dashboard"></i> <span class="menu-text"> Dashboard </span> </a> That means that inside the anchor tag, is as well a <i> -Tag and a <span> -Tag. Is it possible to use the {{ link_to_route }} -Method, without having to change the layout of the Template? 回答1: Use URL:

Displaying the Error Messages in Laravel after being Redirected from controller

谁说胖子不能爱 提交于 2019-11-30 05:52:23
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'); $data = Input::except(array('_token')) ; $rule = array( 'firstname' => 'required', 'lastname' => 'required', ) ; $validator = Validator::make($data,$rule); if ($validator->fails()) { $messages = $validator->messages(); return Redirect::to('/')->with('message', 'Register Failed'); } else { DB::insert('insert into user (firstname, lastname) values (?, ?)', array(

Laravel Blade passing variable with string through @include causes error

和自甴很熟 提交于 2019-11-30 04:10:47
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 get the following error... FatalErrorException syntax ... error, unexpected ',' I've narrowed down that the error is solely from the "(" in the "mainContent" variable string, and when I remove the "(" the error disappears and everything runs fine. I can't find anything in documentation on this or any similar errors listed online. Does anyone know if this is expected

Blade view not reflecting changes

安稳与你 提交于 2019-11-30 02:57:59
I am developing a Laravel(5.2.29) project in Windows environment and testing it on Chrome browser. I have made some changes on a Blade file using atom text editor and then refreshed my page and noticed that suddenly it has stopped reflecting the changes (it's loading the old Blade file). I've tried the following: Restarted the browser Clearing browser cache Running php artisan cache:clear Running composer dumpautoload Deleting the Blade file (and got a view not found error). Then created a new Blade file with the same name, with no content and refreshed the page. No matter what, the code

Laravel 4 blade drop-down list class attribute

℡╲_俬逩灬. 提交于 2019-11-30 02:52:44
Laravel blade drop down list class attribute not working. I cannot find any reference to class or assigning attributes to select / drop-down lists in the documentation. http://www.laravel.com/docs/html#drop-down-lists Examples tried: {{ Form::select('product_id', $productList, array('class'=>'form-control')) }} {{ Form::select('product_id', $productList, $attributes = array('class'=>'form-control')) }} Both return the same html but without the class attribute: <select id="product_id" name="product_id"> ... Option Stuff ... </select> {{ Form::select('product_id', $productList, null, array(

Using Laravel 5 with AngularJS blade tag conflict

不问归期 提交于 2019-11-30 02:37:46
问题 I am trying to setup Angular with Laravel 5. I have tried doing in appServiceProvider: public function boot() { \Blade::setRawTags("[[", "]]"); \Blade::setContentTags('<%', '%>'); // for variables and all things Blade \Blade::setEscapedContentTags('<%%', '%%>'); // for escaped data } With: <div> <input type="text" ng-model="yourName" placeholder="Enter a name here"> <h1>Hello, {{ yourName }}!</h1> </div> But I'm getting: Use of undefined constant yourName - assumed 'yourName'... 回答1: When

How to echo a default value if value not set blade

夙愿已清 提交于 2019-11-29 22:50:00
I would like to know what would be the best way to display a default value if the given value is not set. I have the following in a blade file (I can not guaranty that the key is set, it depends on a multitude of factors). {{ $foo['bar'] }} I would know if the following is the best way to go about it, {{ (isset($foo['bar']) ? $foo['bar'] : 'baz' }} or is there a better way to do this? Thanks :) Use php's null coalesce operator: {{ $variable ?? "Default Message" }} Removed as of Laravel 5.7 With Laravel 4.1-5.6 you could simply do it like this: {{ $variable or "Default Message" }} It's the same

POEdit doesn't extract string in HTML tags

◇◆丶佛笑我妖孽 提交于 2019-11-29 20:06:53
问题 I'm having a problem with Laravel's blade templating syntax. When having something like: <input placeholder="{{ __('My Tooltip') }}" /> that string won't be founded by POEdit. But on same file if I had this: <span>{{ __('My Tooltip') }}</span> that's OK. I've already added a new extractor with follow configs but the problem persists. Command: xgettext --language=Python --add-comments=TRANSLATORS: --force-po -o %o %C %K %F An item in keywords list: -k%k An item in input files list: %f Source