component and slot

使用:

1.component panel

<article class="message">
<div class="message-header">
<p>Hello World</p>
<button class="delete" aria-label="delete"></button>
</div>
<div class="message-body">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. <strong>Pellentesque risus mi</strong>, tempus quis placerat ut, porta nec nulla. Vestibulum rhoncus ac ex sit amet fringilla. Nullam gravida purus diam, et dictum <a>felis venenatis</a> efficitur. Aenean ac <em>eleifend lacus</em>, in mollis lectus. Donec sodales, arcu et sollicitudin porttitor, tortor urna tempor ligula, id porttitor mi magna a neque. Donec dui urna, vehicula et sem eget, facilisis sodales sem.
</div>
</article>

2.其中header和body需要传入变量

<article class="message">
<div class="message-header">
<p>{{$title}}</p>
<button class="delete" aria-label="delete"></button>
</div>
<div class="message-body">
{{$content}}
</div>
</article>

3.views.components.index 中 需要引用component模版panel

@component('components.panel')
@slot('title')
hello world
@endslot
@slot('content')
have a nice day
@endslot
@endcomponent

4.如果要传入默认content

panel.blade.php修改如下:

 <article class="message">
<div class="message-header">
<p>{{$title}}</p>
<button class="delete" aria-label="delete"></button>
</div>
<div class="message-body">
{{$slot}}
</div>
</article>

index.blade.php修改如下

@component('components.panel')
@slot('title')
hello world
@endslot
have a nice day
@endcomponent //可多来几个: @component('components.panel')
@slot('title')
hello world
@endslot
have a nice day123
@endcomponent

5.还可以这样给默认值:title默认为laravel

panel.blade.php修改如下:

     <article class="message">
<div class="message-header">
<p>{{$title ?? 'laravel'}}</p>
<button class="delete" aria-label="delete"></button>
</div>
<div class="message-body">
{{$slot}}
</div>
</article>
index.blade.php修改如下 @component('components.panel')
have a nice day
@endcomponent

最新文章

  1. ABP理论之CSRF
  2. Android之SqlLite数据库使用
  3. winform窗体(二)——控件
  4. swift基础:第五部分:函数与闭包(补充)
  5. 基于Autofac, Castle.DynamicProxy的动态WCF解决方案(原创)
  6. Linux 网络编程详解七(并发僵尸进程处理)
  7. IntelliJ IDEA中使用综合使用Maven和Struts2
  8. HTTP路由
  9. 【BZOJ】【2005】【NOI2010】能量采集
  10. POJ_1742_Coins_(动态规划,多重部分和)
  11. 窗体前端显示(ShowWindowAsync有许多优点)
  12. 提示constructor无法location的原因
  13. 对java中classloader使用的一点理解(转)
  14. JavaWeb(二)cookie与session的应用
  15. linux学习(JDK,Tomcat,nginx)安装
  16. java~集合的介绍和使用
  17. while true 死循环判断端口按顺序启动应用
  18. FutureTask类
  19. 第九篇——Struts2的拦截器
  20. [Algorithm] Warm-up puzzles

热门文章

  1. 对gridview绑定数据的操作方法及自定义显示内容
  2. Java MVC框架性能比较
  3. SQL——视图、事务、锁、存储过程
  4. pthread Win32多线程编程的一些知识和感想
  5. widows&amp;l ubuntu 简单互联——基于samba
  6. js 发送短信验证码倒计时
  7. pycharm激活2018
  8. OpenGL C#绘图环境配置
  9. Python学习-列表的转换和增加操作
  10. PHP:GD库 生成验证码图片