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) !!}
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.
Sometimes, in HTML, I need to avoid adding extra white space, but I also need to add "#if()" blocks. In order to accomplish this, I've taken this approach:
some text{--
--}#if($someCondition){--
--}more text with no space between
#endif
And this approach has been working great. However, after upgrading my development and live environments to Laravel 5.5 (from Laravel 5.2) the Development environment works fine, but the live environment renders the above blade into the following HTML:
some text#if($someCondition)more text with no space between
<?php endif; ?>
... So the "if" statement immediately after the blade comment is left as plain text.
I know that it's possible, because both my development environments render the page correctly. I've looked at PHP versions and copied over the entire code directory, but I cannot find any difference between them at all, let alone a difference that would cause this to be processed differently.
Is there any reason why Laravel's blade engine wouldn't allow a "#" right after blade comment?
Using PHP 7.029, Laravel 5.5, CentOS.
I've discovered the issue. The view was cached on the development environments, which is why it was working.
It looks like there was a new bug introduced in Laravel somewhere between 5.3 and 5.5. The blade comments are being removed before the rest of the blade is analysed, which can cause issues as I showed in the question here. This was working previously in Laravel 5.2.
I did find a work around:
some text{{null
}}#if($someCondition){--
--}more text with no space between
#endif
Produces something that works:
some text<?php echo e(null); ?><?php if($someCondition): ?>more text with no space between
<?php endif; ?>
An alternative way to solve the original issue would be to directly write some PHP code for your if statements:
some text<?php
if($someCondition):
?>more text with no space between<?php
endif;
?>
(however, I agree this is not the sweatest way to write templates, as you will have a mix between Blade and PHP)
Laravel converts your blade templates into PHP, then use these converted files for rendering. So if you write directly some PHP code with your Blade templates, it will just work the same.
Could always use the Blade native php enclosures...
some text{{ if(condition) {do something} }}more text
This gives the the flexibility of inline php with your HTML.
I have been looking for a way to use Laravels Blade templating engine with non PHP file extensions (instead of file_name.blade.php being able to use file_name.blade.js or file_name.blade.css) to no avail. I found a post that seems to describe how to do exactly this for Laravel 4, however it no longer seems to work in Laravel 5. The reason why I would like to do this is I have a Javascript file that looks something like this:
//JS stuff
#foreach($Model->Values as $Value)
{{ $Value->name . " = " . $Value->content . ";"}}
#endforeach
//More JS stuff
And a blade/php file that looks something like this:
//Blade stuff
<script type="text/javascript">
#include('js');
</script>
And this seems to be the nicest way of passing each value to javascript. Even if there is a nicer way of passing these values to javascript, the reason behind this question is to find if there is a way to parse a non PHP file with blade as I think that could be immensely useful.
I thought View::addExtension('blade.js', 'blade') would work in L5 as well. The method hasn't changed. But do note you'll want the blade engine, not the html one like in the post you linked to. Where to put it is a good question, though. Also, you mentioned your two files have the same name before the extensions - that might screw it up, too.
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
Firstly i want to explain how my script works..
I'am using script named TSUE and source code protect by ioncube. Script has own plugins system kind of like vbulletin's Addons system. For using this system i need to create new php function to get data from database and i need to create a template for use(show) them as i want.
I created very simple plugin sample code. I'm getting tid and added coloum in tsue_torrents table with this function;
and using by this template i can show this data which page i want!
here is template
(template name is example btw. need to call that template using by eval in function)
<div class="widget">
<h4>Plugins Example</h4>
<br />
{$output}
</div>
Everything is look fine
But when i add this plugins on my main page or anypage of script I getting error like this;
��\IsG�>��%x!��n�(.���d)D�94��]J��]�$A����4a}�.sҍ��z_VU/ #��/��#-�YYY�U�w��|������~�ܦ�Lz���ѷk����SK�z��н� �ч�v)7�q�m"���u�c&O:�$B�����Nm���œ �m6OOO<!І�/rP�V�5��f�� �s%�#;�� �4MT*S_t���=�����n������˷��7��D�Lw���4S�l�w�%#u��� Ⱥ/����p?�S�s�]�?o �c_�=�~*�u4�]��/*�'B-<[�<�T�ϓ�J'S`�>w�*?s���/�1K�ߩ�9j$:_��F<���O:��g~G79��~t���1��8�|��$��b?��H�T����L:)pq�C���P�4����Ӑ�+G|(zC�C�&�8�:�����9je)!����$�1�)�g1��p�B���̐g!-��N���D*' �Q*�o5�NJ<'%Ha��v,#A_$<���φ2��F�z.O�0J$��&.k,����6]�M�'9��&B#��*�4���Yʾ�Q�i� ���A�P��yV�n��ݴ��tJ?�&8�mO�h�3�ד(Jk�h��iVY��8v��Ô��k��Gˌ����B���b�5�"}��g��c>��vU�}���.l�:h��� `k��4KB=Ȃo�K 0QCz##=;���k�& 7m�+�Q4n�"m�I��E��x�>>�zNO���Ta�M䉆�H�}��v9k�Ӫ���a+�+��#��R����=h7-�H�����R�S�3�a���O�zݨʜ�Ԩu�Ғ��ԮL�mI>i��#�n��f��Juj�=_��0<��zyj�U�9�Z�k�y��H��J�0>����'8L�Z?K�(��QF�B7�������E�uB:�$�i����m�hV�F��AHU�փ� �,�!��wjZ�U��6�pH8y��#OOe� c��5C��\�ɼ :�.���Q]$�lm����%��I�=� ���C��Р��#O�89Pk5����M����f�]_�cc
Screenshot :
Okay; I found why i get that weird error.
I think it is because Dreamweaver CS6.. I don't know excatly reason but when i type my code another php editor , function work fine..