Laravel 5.4 Blade引入了组件和插槽的概念 - 但我看不出它们在传统的@include上添加了什么.据我所知,使用组件/插槽,您可以:
在模板component-tpl.blade.php中:
<div class='container'>
<h1>{{$slot1}}</h1>
<h2>{{$slot2}}</h2>
</div>
Run Code Online (Sandbox Code Playgroud)
使用页面模板中的插槽,您可以:
@component('component-tpl')
@slot('slot1')
The content of Slot 1
@endslot
@slot('slot2')
The content of Slot 2
@endslot
@endcomponent
Run Code Online (Sandbox Code Playgroud)
与旧版本相比,它提供了哪些功能:
@include('component-tpl',['slot1'=>'The content of Slot 1',
'slot2'=>"The content of Slot 2"])
Run Code Online (Sandbox Code Playgroud)
使用完全相同的'component-tpl.blade.php'刀片模板?
我错过了什么?感谢您的任何见解.
克里斯
Laravel刀片下拉列表类属性不起作用.
我找不到任何类的引用或为文档中的选择/下拉列表分配属性.
http://www.laravel.com/docs/html#drop-down-lists
试过的例子:
{{ Form::select('product_id', $productList, array('class'=>'form-control')) }}
{{ Form::select('product_id', $productList, $attributes = array('class'=>'form-control')) }}
Run Code Online (Sandbox Code Playgroud)
两者都返回相同的html但没有class属性:
<select id="product_id" name="product_id">
... Option Stuff ...
</select>
Run Code Online (Sandbox Code Playgroud) 在Laravel Blade中,我们基本上可以这样做:
@section('mysection')
@endsection
@section('mysection')
@stop
Run Code Online (Sandbox Code Playgroud)
@stop和之间有什么区别@endsection?
如何在Laravel中重定向的视图中显示验证消息?
这是我在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($firstname, $lastname));
return Redirect::to('/')->with('message', 'Register Success');
}
}
Run Code Online (Sandbox Code Playgroud)
我知道下面给出的代码是一个糟糕的尝试,但我怎么能解决它,我错过了什么
@if($errors->has())
@foreach ($errors->all() as $error)
<div>{{ $error }}</div>
@endforeach
@endif
Run Code Online (Sandbox Code Playgroud)
我对Laravel,MVC和模板引擎一般都是新手.
如果用户已登录,我需要显示某些导航栏按钮和选项,例如:通知,注销,配置文件等...否则会显示"登录"按钮.
如何以正确的方式解决这个问题的任何帮助都非常感谢.这就是我现在正在考虑的事情:
User对象总是传递给视图.User已设置(意味着已登录)以包含导航栏的相应部分刀片模板.app.blade.php:
...
@if (isset($user))
@include('partials.navbarlogged')
@else
@include('partials.navbar')
...
Run Code Online (Sandbox Code Playgroud)
这是最好的方法吗?谢谢你的时间!
我必须在Laravel 5 Blade Template中放置一些PHP代码.如下
@foreach ($farmer->tasks as $task)
@if ($task->pivot->due_at) < date(now))
$style = 'alert alert-danger';
@elseif ($task->pivot->due_at) > date(now))
$style = 'alert alert-success';
@else
$style = '';
@endif
@endforeach
Run Code Online (Sandbox Code Playgroud)
将PHP代码放在Laravel 5 Blade Template中的实际过程是什么?
我正在Windows环境中开发一个Laravel(5.2.29)项目并在Chrome浏览器上进行测试.
我使用原子文本编辑器对Blade文件进行了一些更改,然后刷新了我的页面并注意到它突然停止反映更改(它正在加载旧的Blade文件).
我尝试过以下方法:
php artisan cache:clearcomposer dumpautoload无论如何,浏览器上显示的代码始终是相同(旧)版本,而不是Blade文件的内容.
我该如何解决这个问题?
如果您查看laravel官方文档http://laravel.com/docs/4.2/templates 它说给出这个布局:
<!-- Stored in app/views/layouts/master.blade.php -->
<html>
<body>
@section('sidebar')
This is the master sidebar.
@show
<div class="container">
@yield('content')
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
通过这种观点扩展
@extends('layouts.master')
@section('sidebar')
<p>This is appended to the master sidebar.</p>
@stop
@section('content')
<p>This is my body content.</p>
@stop
Run Code Online (Sandbox Code Playgroud)
将附加到该部分sidebar.但实际上如果你尝试它不会附加,它只是覆盖扩展模板中的内容.
我听说过其他刀片功能@append, @prepend, @parent......似乎没有人工作.
除此之外,官方文档中的这个例子不起作用,我发现刀片文档非常差.例如@parent,刀片功能没什么.
我正在使用具有本地化功能的laravel(5.1)刀片模板引擎.
有一个语言文件messages.php的内部/resources/lang/en/文件夹:
return [
'welcome' => 'welcome',
Run Code Online (Sandbox Code Playgroud)
在我的刀片模板中,使用以下trans方法调用欢迎消息:
{{ trans('messages.welcome') }}
Run Code Online (Sandbox Code Playgroud)
在某些情况下,我需要显示相同的消息,但首字母大写("欢迎").我不想在翻译文件中使用重复记录.
我怎么处理这个?
我想在输入值中显示旧输入.如果没有旧输入,则显示其他变量:
value="{{ old('salary_' . $employee->id) or 'Default' }}"
Run Code Online (Sandbox Code Playgroud)
但是当没有旧输入时,它会给我1而不是默认值!
我认为问题与串联有关,但我不知道如何解决它!?
blade ×10
php ×8
laravel ×7
laravel-4 ×3
laravel-5 ×2
html-select ×1
laravel-5.1 ×1
laravel-5.4 ×1