I am unable to find what is the problem. HTML tags are inside the PHP, but not working as expected:
<td>{{$trade->is_action==1 ? 'Bought' : '<?php echo "<span class='badge-pill' style='background-color:#f44336' >" ?> Sold <?php echo "</span>" ?>' }}</td>
From the image, you can clearly check it.
OUTPUT:
With the above solution of u_mulder, I would like to add to it. If you want to display HTML in blade, use {!! !!}:
<td>{!! $trade->is_action==1 ? 'Bought' : '<span class="badge-pill" style="background-color:#f44336"> Sold </span>' !!}</td>
To explain further, you don't need to use PHP inside the blade syntax.
Blade {{ }} means that you output data already, there's no need to use <?php and echo, Blade does that for you, just provide a string that you want to output:
<td>{!! $trade->is_action==1 ? 'Bought' : '<span class="badge-pill" style="background-color:#f44336"> Sold </span>' !!}</td>
Update: to output raw html - use {!! !!} instead of {{ }}.
Related
im calling v-for event on div tag to create <a> tag by every object on results array
Code attempt:
results array:
html (Laravel blade):
#verbatim
<div class="category-item" v-for="result in results" :value="result.id">
<a class="button-product-info-s" href="/product/{{ result.id }}"/>{{ result.name }}</a>
</div>
#endverbatim
brower output:
as you can see {{ result.name }}} is just working and {{ result.id }} is not outputing anything
i tried using .{{ result.id }}. but didn't work
Have you tried changing your href attribute to :href="'/product/'.result.id"?
Or with the + operator instead of .
Change your code to something like:
#verbatim
<div class="category-item" v-for="result in results" :value="result.id">
<a class="button-product-info-s" href="/product/#{{ result.id }}"/>#{{ result.name }}</a>
</div>
#endverbatim
I am having following html code in blade file:
#foreach ($engagements as $engagement)
{!! Form::checkbox('engagements[]', $engagement->id, in_array($engagement->id, $user->privileges->pluck(engagement_id)->toArray()) ? true : false) !!} {{ $engagement->name }}
{!! Form::select('roles[]', $userRoles, $user->privileges->where(engagement_id, $engagement->id)->first()[role]) !!}
#endforeach`
I want to pass $engagement->id in roles[] as roles[{{#engegement_id}}]
However, instead of displaying value of {{#engegement_id}}, it is showing it as roles [{{#engegement_id}}] in html view source.
What am I doing wrong here?
Try with this,
#foreach ($engagements as $engagement)
#php echo $roleWithId = roles[$engagement->id] #endphp
{!! Form::checkbox('engagements[]', $engagement->id, in_array($engagement->id, $user->privileges->pluck(engagement_id)->toArray()) ? true : false) !!} {{ $engagement->name }}
{!! Form::select($roleWithId , $userRoles, $user->privileges->where(engagement_id, $engagement->id)->first()[role]) !!}
#endforeach
Make string which you want to pass and store it in variable and pass that variable in Form select.
Hope this helps :)
We can not do like this, it is giving as error saying 'Undefined variable roles' for #php echo $roleWithId = roles[$engagement->id] #endphp. However, I tried it in select itself as
{!! Form::select('roles[#php echo $engagement->id #endphp]', $userRoles, $user->privileges->where(\App\Privilege::COLUMN_ENGAGEMENT_ID, $engagement-> {\App\Engagement::COLUMN_ID})->first()[\App\Privilege::COLUMN_ROLE]) !!}
However, it is showing it as
<select name="roles[<?php echo $engagement->id ?>]"> in view source
Okay so I have the following (multiple times) in my blade template:
{{ Auth::user()->settings['font'] == null ? "<span class='fa fa-check'></span>" : false }}
However it doesnt render the span statement, it simply prints it out. I've read elsewhere that to render HTML in a blade template I need to use {!! <span></span> !!} but how can I do that within a shortcut IF statement?
The {{ $thing }} syntax escapes the content passed to it via the e() helper. You can use the following alternative syntax: {!! $thing !!}
This syntax works the same as the first one so you can use your ternary condition too. The following will print nothing if the condition is not met.
{!! Auth::user()->settings['font'] == null ? "<span class='fa fa-check'></span>" : '' !!}
Alternatively with #if:
#if(Auth::user()->settings['font'] == null)
<span class='fa fa-check'></span>
#endif
I want to put a line break into a blade report.
I know there is the {!! !!} tags to escape the html tags, but in my situation I have a long string coming in at {{$row[$colField]}} so it already within {{ }} tags.
The way I tried it would have appeared like {{ randome text {!! <br/> !!} }}.
Is there any other way to do this perhaps.
#foreach($fieldList as $field)
#if ($header->group == $field->group)
<?php $colName = $field->columnname ?>
<?php $colField = $field->columnfield; ?>
<?php $fieldGroup = $field->group; ?>
#if ($colName != $fieldGroup)
<span class="titleSpan" style="white-space: nowrap; font-weight: bold">{{ $colName=='Age'?'':$colName.':' }} </span>
#endif
{{$row[$colField]}}<br>
#endif
#endforeach
The curly brace blade tags are for echoing values, they don't do anything else and you cannot nest them in the way you're trying to in your example. You can find information about these tags in the Blade documentation, but in summary:
The double curly brace tag means echo this value and escape it, e.g:
{{ $row[$colField] }}
compiles to:
<?php echo e($row[$colField]); ?>
A curly brace with 2 exclamation marks means echo this value without escaping it, e.g:
{!! $row[$colField] !!}
compiles to:
<?php echo $row[$colField]; ?>
If you would like for a line break (<br/>) to appear somewhere within the value of $row[$colField] then you must transform that value before outputting it. There are functions, like nl2br that can replace new lines with line breaks, so you could for example do this:
{!! nl2br($row[$colField]) !!}
Which would compile to:
<?php echo nl2br($row[$colField]); ?>
So if the value of $row[$colField] is:
Hello world
This is another line.
Then that code would output:
Hello world</br>
This is another line.
That said your question is unclear so if this information does not help then please rewrite your question to clearly communicate what you're trying to achieve, i.e: include an example of your input and an example of your desired output.
So i am currently working with nl2br. I don't know whether this is a bug, or a wrong way to doing things from my side but i encounter this. First of all, here's the snippet :
#foreach($dataList as $data)
<div class="productDesc">
{!! nl2br(e($data->product->description)) !!}
</div>
#endforeach
When i run this, the output is only the description of the first product. I initially thought there's something wrong with my code but when i do a debug like this :
#foreach($dataList as $data)
{{ $data->id }}
<div class="productDesc">
{{ $data->id }}
{!! nl2br(e($data->product->description)) !!}
</div>
{{ $data->id }}
#endforeach
The result in the 2nd row is :
2
1 This is a description for 1st product
2
As you can see, it somehow ignore the forwhile loop parameter. Can someone inform whether there's a solution for this or am i just code it wrongly ?