This question already has answers here:
Blade engine: print triple curly braces
(5 answers)
Closed 4 years ago.
I want to print double curly brackets from a Laravel blade template. Here is what I've tried so far and failed:
#{{ n }}
{!! '{{ n }}' }}
#php echo '{{ n }}'; #endphp
#php echo '{{ n }}'; #endphp
Here is the view I have:
<div class="new-page">
<div class="row">
<div class="col-sm-4"></div>
<h3 class="col-md-6 center">Page #if(isset($n)) {{ $n }} #else #{{ n }} #endif</h3>
</div>
</div>
Weirdly, when I try any of the above there is no error it just displays an empty page.
I am using Laravel 5.6, I've also tried googling but no solution worked.
It turns out the default app.js file that comes with Laravel is throwing an error and it is breaking the page - I don't know exactly why though. The error is as follows:
n is not defined
Page <?php if(isset($n)) echo "{{ ".$n." }}"; else echo "{{ ".n." }}"; ?>
This will work quite fine you can check below screenshots
Try once using php tag like
<?php if(isset($n)) echo $n; else echo "{{ n }}"; ?>
Can you not do something like:
#php echo "{{" . {{ $n }} . "}}" #endphp
The question being is n a variable passed in or created by a controller or declared earlier in the view?
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
What is the correct way to call the "Links" function after this "Foreach"?
I don't know how to handle the variable to put in function.
#inject('usuarios', 'App\User')
#foreach($usuarios->getIndicados() as $user)
#endforeach
<div class="row">
<div class="col-12 text-center">
{{ $usuarios->getIndicados()->links() }}
</div>
</div>
Maybe it's just an editing error, but in your output the -tags don't seem to be closed again. Also, there should be no space like < a> at the beginning of the tag. And < a hr_ef= ... is obviously wrong.
In order to style them, you can add a class attribute to the tags while building the string and do the style-stuff in css.
This is what laravel document provides. You need to add links in the collection.
<div class="container">
#foreach ($users as $user)
{{ $user->name }}
#endforeach
{{ $users->links() }}
This question already has answers here:
PHP code is not being executed, but the code shows in the browser source code
(35 answers)
Closed 4 years ago.
this is my blade showing codes instead of the interface that i wanted to show :
https://i.stack.imgur.com/JSMzL.png
this is my blade
<div class="container">
<div class="row">
#foreach($details as $details)
<tbody action="{{!! action('DestinationDetailsController#details') !!}}" method="get">
<img src="{{!! asset('img/admin/' . $details->dest_img) !!}}" alt="Opps..." style="width:70%;">
<h2>{{!! $details->dest_name !!}}</h2>
<p>{{!! $details->dest_desc !!}}</p>
</tbody>
#endforeach
</div>
this is my controller looks like
public function details($id = null)
{
$details = DB::table('destinations')->where('dest_id',$id)->first();
return view('destinationdetail')->with('details', $details);
}
im very new in development world so i really need to learn from this kind of simple mistakes :)
{{!! action('DestinationDetailsController#details') !!}}
Should be:
{!! action('DestinationDetailsController#details') !!}
Basically when using !! you only use one bracket.
You should however use:
{{ action('DestinationDetailsController#details') }}
unless you really don't want to escape the data.
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.
I'm using Laravel and Blade on a small project and am trying to dynamically assign class names to generated elements in a for loop. However, the generated elements are generating literally, such as "<div class='form_q' .$i>".
#for($i = 0; $i < count($formdata['form2']); $i++)
<div class='form_q'.$i>
HTML::attributes('class')
<div class='q'.$i.'-header'>
<h1>{{ Form::label($formdata['form2']['q'.($i + 1)]['question'], $formdata['form2']['q'.($i + 1)]['type'], array('class' => 'btn btn-primary'))}}</h1>
</div>
</div>
#endfor
What's the proper syntax for concatenating a string and variable and assigning it to an class/attribute? Alternatively, what is the proper Blade syntax for generating a "div" element with an assigned class?
You need to tell Blade or PHP you want to print the output.
Ether surround the $i variables like {{ $i }} or like <?php echo $i ?>. Blade just converts back to PHP for example, {{ }} is converted into <?php echo ?>. Keep in mind that you're still using PHP when making Blade templates.
#for($i = 0; $i < count($formdata['form2']); $i++)
<div class='form_q{{ $i }}'>
HTML::attributes('class')
<div class='q{{ $i }}-header'>
<h1>{{ Form::label($formdata['form2']['q'.($i + 1)]['question'], $formdata['form2']['q'.($i + 1)]['type'], array('class' => 'btn btn-primary'))}}</h1>
</div>
</div>
#endfor
You should go over the Blade docs again. http://laravel.com/docs/templates
I don't know laravel or blade, but I think you should use double curly brackets to echo a php variable, like this:
<div class='form_q'{{$i}}>
{{ $i }} = <?php echo $i ?>
Example for image BLADE with Array php
{!! Html::image( asset('/profile/'.$u->foto), 'Profile', array('class' => 'avatar;')) !!}