Laravel-检查@yield是否为空 [英] Laravel - Check if @yield empty or not

查看:252
本文介绍了Laravel-检查@yield是否为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在刀片视图中查看@yield是否具有内容?

Is it possible to check into a blade view if @yield have content or not?

我正在尝试在视图中分配页面标题:

I am trying to assign the page titles in the views:

@section("title", "hi world")

所以我想签入主布局视图...类似

So I would like to check in the main layout view... something like:

<title> Sitename.com {{ @yield('title') ? ' - '.@yield('title') : '' }} </title>

推荐答案

可能有更漂亮的方法.但这可以解决问题.

There is probably a prettier way to do this. But this does the trick.

@if (trim($__env->yieldContent('title')))
    <h1>@yield('title')</h1>
@endif

这篇关于Laravel-检查@yield是否为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆