I would like to remove the stripslash "\" character from my database search result.
Instead of using {{stripslashes($output->var)}}, which add a PHP function on every output in blade, can I do it GLOBALLY in the BladeCompiler file?
I want to apply this change in every output {{ }} in my Laravel site, any suggestion? I tried to modify the Bladecompiler file compileRegularEchos function, seems not working, please advice
I'm assuming you're using Laravel 5 because Blade templating defaults to escaping now. If you want to echo something without escaping you can use this syntax:
{!! $output->var !!}
For more info you can check the Blade docs
Related
I want to cleanup my php file. I really like the way how blade template use curly brace to display php variables {{ $user }} https://laravel.com/docs/5.8/blade#displaying-data
Is there a way to use a functionality like that without using blade template. Using <?php echo $user ?> get's very repetitive.
This is not possible in PHP without using a template engine because it is a different syntax. Anyway in my opinion sometimes it is not the best idea to use a template engine because PHP is already kind of a template engine.
All what you seem to care about is the short syntax of echoing a variable in blade:
{{ user }}
This is as short as the syntax the PHP template engine itself provides:
<?= $user ?>
Of course Laravel (and similar) has a good reason to use template engine like blade - in order to seperate controller, logic and view (such that the view can be made by non-programmer designers for instance).
Update (thx to comments): The codes provided above do not exactly do the same as template engines (as an additional layer) may take care of e.g. escaping variables, which adds safety to the code.
As the OPs' code has already been built with echo and he is just searching for a replacement I did not mention this, but its a notable difference that you have to take care of some things yourself if not using one.
I have HTML code in the database. I need to paste PHP code into that HTML. The problem is when I try to do it I see nothing instead of code I pasted. I tried "<?php ?>" but seems Laravel uses some escaping to avoid any code injections from the database entries. How can I disable it? Or maybe there is some way to get database content without any changes.
Also I tried "#php #endphp" and "{!! !!}}" but blade.php doesn't handle these constructions and show it as is. I think blade transforms into php rather than Laravel handle blade syntax of pasted content.
Storing HTML in the DB is not a good idea. But, if you really want to do it, try this:
{!! html_entity_decode($htmlCode) !!}
I'm currently making a simple file hosting script using Slim, Twig, and PHP. Right now I'm trying to append onto the current URL using Twig but am not sure how to do this. I've tried /panel/{{ newURL }} but it always just redirects me to /panel/newurl. I need to be able to dynamically update this URL.
For example, if I want to go to /tests on /panel/core/ I need to be able to append that onto the current URL. Does Twig offer a way to do this? Thanks.
Do you use Twig to render your paths? I think your application should always be able to resolve the paths, so also let the application itself render them ;-)
If that would help; you can add the parameters of the current request to the path rendering:
{{ path('yourpath', app.request.query.all|merge({'myparam': 'value'})) }}
you can use the Built-in parameter in twig {{ app.request.uri.path }}
You'll want to ensure that you've included all route and query string parameters in the URL you're appending to.
Here's an example of appending foo=bar to the current URL:
{{ path(app.request.attributes.get('_route'), app.request.attributes.get('_route_params')|merge(app.request.query.all)|merge({'foo': 'bar})) }}
I ended up just passing 'url' => $request->getUri()->getPath() in my view parameters. I think this is a pretty decent method because there are other methods you can call on getUri() to get different results depending on what you want to do.
I am using Laravel and AngularJS for my project. I changed the Angular curly brackets to {[{ because of, blade uses the same. I got some data with an $http.post() in AngularJS and I want to print this data in my views, witch I have made in Laravels blade. Because of, I am printing data from AngularJS I am using ng-repeat:
<tr ng-repeat="school in data.result">
<td>{[{ school.name }]}</td>
<td>{[{ school.brin }]}</td>
<td>{[{ school.city }]}</td>
<td>{[{ school.phonenumber }]}</td>
</tr>
This works fine. The problem is: how can I print an value inside {{ URL::to('scholen/bekijk/') }}?
Something like:
{{ URL::to('scholen/bekijk/'. {[{ school.id}]}) }}
I tried a lot, but I got errors only ;)
Something like:
{{ URL::to('scholen/bekijk/'. {[{ school.id}]}) }}
You can't.
Why? Blade is processed with PHP, which is server-side.
AngularJS processes client-side, once any/all Blade processing is completely finished.
that is because
{{ URL::to('scholen/bekijk/'. {[{ school.id}]}) }}
this code is interpret by php. but the syntax is incorrect acceding to php. because php accepts {[{ school.id}]}) part as a interpret-able php thing but its not. if u can put {[{ school.id}]}) inside the string then php is not going to interpret is because its know its just a string. but in angular side angular knows that's is a something that angular should do because the string includes {[{ school.id}]}) .
so u can try something like,
{{ URL::to('scholen/bekijk/{[{ school.id}]})' }}
You should really pick one and stick with it, by that I mean don't try and mix Blade and Angular. If you want to go with Angular pages, then make them all Angular, not some kind of Blade-Angular hybrid.
When working with Angular and Laravel I completely remove any view logic from Laravel, and use it purely as the back-end logic. Angular is responsible for all the view templating and rendering.
I suggest don't mix angular and blade...
Look at this: https://github.com/Ferticidio/UPEnews/blob/master/app/views/indexangular.blade.php only load angular...
and: https://github.com/Ferticidio/UPEnews/tree/master/public
In public i push all the angular logic...
This was very fast and comprensive for me..
So my dilemna is this.
<p>Email: info#example.com</p>
Is being processed as blade code and won't re-size in my responsive bootstrap web page in my Laravel 4 framework.
Any ideas on how to get blade to ignore the # symbol? It is probably a simple fix I just can't find it on the web.
Thanks
A really simple way would be this:
someone{{'#'}}email.com
{{ $whatever }} effectively gets transformed into <?= e($whatever) ?> (where e() does HTML escaping) so you can put a string there, and that will get output instead of a variable.
The following will avoid blade syntax:
<p>Email: info<?php echo urldecode('%40')?> example.com</p>
%40 is equivalent to #
There are also HTML helpers in Laravel,
you can use the following to generate a mailto tag with an obfuscated email address:
# Generating obsufscated mailto tag
{{ HTML::mailto('myemail#mail.com','Some person'); }}
// Generates :
Some person
View more of these helpers at http://www.laravel-tricks.com/tricks/generating-html-using-html-methods