R
R
Roman2019-01-05 23:16:17
Laravel
Roman, 2019-01-05 23:16:17

How to enter a variable into a blade template by condition?

Hello. It is necessary that the standard title be displayed on the page, if it is not defined for this particular page. I'm trying to write a simple condition in the template {{ $title or 'Default' }} in the title tag. But this construction returns the value 1. If only {{ $title}} is left, everything is displayed normally. How can this issue be resolved?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
part_os, 2019-01-06
@part_os

{{ $title ?? 'Default' }}
Have you tried it?

J
jazzus, 2019-01-05
@jazzus

@if ($title)
     {{ $title }}
@else
'Default'
@endif

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question