I can generate a basic link like so:
This is an [example link](http://example.com/).
I can generate a button with a dynamic link like so:
#component('mail::button', ['url' => \URL::to('/subscriptions/'.$recipient->id.'/'.$recipient->email.'?action=subscribe')])
Sign Me Up
#endcomponent
But how do I generate a dynamic link, not button?
I tried:
[Safe Unsubscribe]( url('/subscriptions/'.$recipient->id.'/'.$recipient->email.'?action=unsubscribe') )
and
[Safe Unsubscribe]( \URL::to('/subscriptions/'.$recipient->id.'/'.$recipient->email.'?action=unsubscribe') )
but these output in a literal way:
url('/subscriptions/'.%24recipient-%3Eid.'/'.%24recipient-%3Eemail.'?action=subscribe%27)
You are still in a blade template. So if you are not in a blade directive and you want to echo content, you have to use the curly brackets.
[Safe Unsubscribe]({{ url('/subscriptions/'.$recipient->id.'/'.$recipient->email.'?action=unsubscribe') }})
Related
I have a problem with my laravel URL
I make a one-user blog, but when I click on modify button the URL is: http://127.0.0.1:8000/ %09 /posts/edit/3
the problem is in /%09/...
this is the route
Route::get('/posts/edit/{post}' , [PostController::class , 'edit'])->name('posts.edit');
and this is the href
href="{{route('posts.edit' , ['post' => $post->id])}}"
see you can pass variable directly with out reference if you have only 1 parameter
like this:
Route::get('/posts/edit/{post}' , [PostController::class , 'edit'])->name('posts.edit');
href="{{ route('posts.edit' , $post->id) }}"
Somewhere in your codebase, there is a Horizontal Tab that is being parsed in URL. This is the reason you are seeing %09.
In a blade file one can do this:
{{ $someVariable }}
This sanitizes $someVariable as opposed to calling it like this:
{!! $someVariable !!}
What PHP function is called for the first case? Is there a way to do this outside of a blade file?
The function that ends up being called is e, for 'escape'.
"Encode HTML special characters in a string."
{{ ... }} is replaced with <?php echo e(...); ?>.
It is defined in vendor/laravel/framework/src/Illuminate/Support/helpers.php. It calls htmlspecialchars but also handles special objects that are Htmlable or DeferringDisplayableValue.
"The e function runs PHP's htmlspecialchars function with the double_encode option set to true by default" - Laravel 9.x Docs - Helpers - String Helpers - e
On a side note, this is not sanitizing, it is just escaping.
According to the Laravel documentation you can do it with htmlspecialchars()
Example:
$new = htmlspecialchars("<a href='test'>Test</a>", ENT_QUOTES);
echo $new; // <a href='test'>Test</a>
https://www.php.net/manual/en/function.htmlspecialchars.php
I have a code <span>{{ trans('lang.color.' . $bet->color) }}</span></div> which displays the bet amount for a specific color.
My lang file:
'color' => [
'red' => 'red',
'zero' => 'green',
'black' => 'black',
],
Which is responsible for the fact that if the bet was placed on red, the site will say: set to red.
How can I correctly display HTML code in color variables? For example, if i write 'red' => '<div style="font-color:#FF0000">red</div>' site does not convert the text to HTML, and writes the div with text. How to make read text file HTML?
My laravel version: 5.1.10.
Displaying Unescaped Data
By default, Blade {{ }} statements are automatically sent through PHP's htmlentities function to prevent XSS attacks. If you do not want your data to be escaped, you may use the following syntax:
{!! trans('lang.color.' . $bet->color) !!}
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.
I have the follow code in Blade using a ternary operator:
<td>{{isset($arrTemp[$ccc->id]) ? "<a hfet='".url('/cc/'.$cc->id)."'>".count($arrTemp[$cc->id])."</a>": 'N/A'}}</td>
If it find somenthing for the array key $cc->id, should thisplay the value with the link atteched to it.
But the page is rendering <a hfet='http://my.test/cc/56526235'>4</a> the string itself.
What am I missing?
When you use {{ }} the output is automatically escaped to prevent XSS attacks. You can use {!! !!} instead, which will not escape the string.
Source: https://laravel.com/docs/5.4/blade#displaying-data
So there must be a simple way around this... On my site there are multiple modals, depending on the page. I've created a modal template that these can all extend. However, the last modal I include on the page ends up 'taking over' the rest of them, and so all my modals end up with the same sections from that last include. How can I make it so that each extension is unique to the file from which it extends?
Example of what's happening:
//template.blade.php
<htmls and stuff>
#yield('section_1')
#yield('section_2')
</htmls and stuff>
//Modal 1
#extends('template')
#section('section_1')
Some words
#stop
#section('section_2')
More words
#stop
//Modal 2
#extends('template')
#section('section_1')
Rabbit
#stop
#section('section_2')
Stew
#stop
Instead of two unique modals being loaded, I end up with two modals full of Rabbit Stew.
Try using the #overwrite command instead of #endsection
Example:
#section('stuff')
Stuff goes here...
#overwrite
Source: https://github.com/laravel/framework/issues/1058#issuecomment-17194530
I personally would use includes in this instance, unless you've got markup in your sections. If it's just text you could do something like this:
//template.blade.php
<htmls and stuff>
{{ $section1 }}
{{ $section2 }}
</htmls and stuff>
//Modal 1
#include('template', ['section1' => 'Some words', 'section2' => 'More words'])
//Modal 2
#include('template', ['section1' => 'Rabbit', 'section2' => 'Stew'])
I had the same problem. I really wanted to use Blade templates too, but ended up using php includes, even with basic html markup.
//Modal 1
#include('layout.template', array(
'section1' =>
'<h1>Modal 1</h1><p><b>Some</b> words</p>',
'section2' =>
'<p>Some <u>words</u></p>'
))
//Modal 2
#include('layout.template', array(
'section1' =>
'<h1>Modal 2</h1><p><b>Some</b> words</p>',
'section2' =>
'<p>Some <u>words</u></p>
'
))
The markup all works just fine, including links. Where I ran into trouble was when I wanted to use includes inside the include arrays, which I understand is not possible. That is why I wanted to use Blade Templates.