In view of 5.7 laravel app with I want to number of items considering plural, like
{{ count($activeVoteCategories) }} vote #if(count($activeVoteCategories) > 1)s #endif
But resulting label is invalid, as there is unnessary space before last "s" symbol:
6 vote s
If I try to get rid of this space like
{{ count($activeVoteCategories) }} vote#if(count($activeVoteCategories) > 1)s #endif
I got error :
syntax error, unexpected 'endif' (T_ENDIF), expecting end of file (View: /mnt/_work_sdb8/wwwroot/lar/
I know that there are plural methods in localization functionality, but this site has no localization, it it always in english...
which is the right way?
Thanks!
Related
Hope you can help me. I'm trying a simple loop in a Laravel blade view and trying to access some data through a relationship.
The DD below outputs 1 as expected, but the echo in the h5 produces the error in the title. I'm stumped!
#forelse($user_adverts as $user_advert)
{{ dd($user_advert->advertLogs->first()->id) }}
<h5 class="card-title">£ {{ $user_advert->advertLogs->first()->id }}</h5>
#empty
<p>No adverts yet :(</p>
#endforelse
If I {{ dd($user_advert->advertLogs->first()) }} I see the model: App\Models\AdvertLog
I'm just confused why I can't output a single column without a null error? Usually that means there is no relationship I thought? I know this is going to be a simple one - your help is appreciated!
You can get rid of the error by changing the card title like this
{{ $user_advert->advertLogs->first()?->id }}
The id will be displayed if you have one, and nothing if there is no advertLogs.
Not sure if this is want you intented to do though.
I'm new to Laravel and am using Laravel 6. One of my views is going to contain the values in a row of my MySQL table. The table column is a boolean so it contains either 0 or 1. Rather than displaying 0 or 1 in the view, I want to display YES or NO. An #if seems the logical way to do this but I can't get my #if to work.
#if ({{ $sleepDiaryEntry->outdoorLight }} == 1 )
<p>Two hours of outdoor light? YES</p>
#else
<p>Two hours of outdoor light? NO</p>
#endif
I've tried several variations of the #if but every variation gives me a syntax error on the first line of the #if.
Unfortunately, the Laravel manual is very skimpy on details of exactly what arguments can and cannot appear in an #if. They tend to give an example or two and think they've anticipated every possible situation and question.
How I can accomplish what I want to do, either with or without #if?
remove {{}} in #if, like followings
#if ($sleepDiaryEntry->outdoorLight == 1 )
<p>Two hours of outdoor light? YES</p>
#else
<p>Two hours of outdoor light? NO</p>
#endif
because {{}} for show the variable
I am not sure about what you want but by using {{}} you are trying to print data.
Try :
#if ($sleepDiaryEntry->outdoorLight == 1 )
<p>Two hours of outdoor light? YES</p>
#else
<p>Two hours of outdoor light? NO</p>
#endif
If it doesn't work:
Are you giving $sleepDiaryEntry to the view in your controller method ?
Try to {{ dd($sleepDiaryEntry) }} see what you have in your view.
#if ({{ $sleepDiaryEntry->outdoorLight }} == 1 ) just gets rendered down to:
<?php if ({{ $sleepDiaryEntry->outdoorLight }} == 1 ) { ?>
in the final Blade template, which will cause a syntax error. You don't need the {{ }} tags in the conditional (not just "don't need": they won't be parsed at all here); it takes plain old PHP code in the ().
I have migrated my app from laravel 4.2 to laravel 5
I am currently having this problem, when even I have old comments like this:
{{--{{link_to_route('language.select', 'English', array('en'))}}--}}
Will result into error at laravel 5, I will have this error:
FatalErrorException in 18b6386ebc018eb0c0e76f105eba4286 line 263:
syntax error, unexpected '{'
which is compiled into:
<?php echo --{{link_to_route('language.select', 'English', array('en')); ?>--}}
I already added laravel 4 backward comparability support at register#ServiceProvider as:
\Blade::setRawTags('{{', '}}');
\Blade::setContentTags('{{{', '}}}');
\Blade::setEscapedContentTags('{{{', '}}}');
but how can I add laravel 4 backward comparability for comments {{-- --}} ?
edit:
how to comment this in laravel 5:
<li {{ (Request::is('/') ? ' class="active"' : '') }}>{{trans('messages.Home')}}</li>
Since you change your content tags from {{ to {{{ comment tags are now {{{-- not {{--
From lavarel 5 doc
Note: Be very careful when echoing content that is supplied by users
of your application. Always use the double curly brace syntax to
escape any HTML entities in the content.
{{-- This comment will not be in the rendered HTML --}}
So I think this should works :
<li {{-- (Request::is('/') ? ' class="active"' : '') --}}>
{{--trans('messages.Home')--}}
</li>
And to comment the whole HTML add :
{{{-- HTML --}}}
In general the comment syntax has not changed in Laravel 5, however...
The characters for comments are derived by the content tags. Since you set them to {{{ and }}} with Blade::setContentTags('{{{', '}}}'); you have to use them now for your comments as well:
{{{-- {{link_to_route('language.select', 'English', array('en'))}} --}}}
Does anyone know how I could get this to work.
My database has some null dates, so I would like to return as empty space.
I currently have this.
{{ Carbon::parse($chauffeur->roadTestCert)->format('m/d/Y') }}
and from what I read about the blade template is that you can use "or 'message'" after it.
I did this.
{{ Carbon::parse($chauffeur->roadTestCert)->format('m/d/Y') or '' }}
in hopes to just show empty space but I get a "1" instead.
Anyone know why and/or how to get around this?
Well, you should rather do it using simple condition:
#if ($chauffeur->roadTestCert !== null)
{{ Carbon::parse($chauffeur->roadTestCert)->format('m/d/Y') }}
#endif
I have a Blade template that loads a list of users and displays their various details.
If a user has no mobile number I want to display the message "No Mobile Number" (I've tried single and double quotes), this never gets displayed:
#if ($person->Mobile >= "")
{{ $person->Mobile }}
#else
'No Mobile Number'
#endif
I tried substituting the "No Mobile" message with {{ $person->EMail }} (which I'm displaying elsewhere, so I know everyone has an email address), but still go nothing, as far as I can tell the logic isn't going into the #else block.
Any ideas?
This should work
#if (!empty($person->Mobile))
{{{ $person->Mobile }}}
#else
'No Mobile Number'
#endif
I use this approach:
#if( isset($error_message) )
#section('content')
#parent
#stop
#section('error_message')
<strong>Holly molly! </strong><em>{{ $error_message }} :(</em>
#stop
#endif
I have a section content and inside content have another section error_message so if error_message variable is set, show that content section and inside print my error_message.
PD: I haven't my original code to hand... Im currently using Twig as primary template engine in Laravel4. Twig beats Blade in simplycity and is very usefull