Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

cloudstudio's avatar

Escape blade bug?

Hi everybody !

I try to print code in blade template without escape. http://laravel.com/docs/5.0/templates#other-blade-control-structures

I use : {!! $company->description !!}

But this is my ouput.

{!! $company->description !!}

Any idea?

0 likes
35 replies
cloudstudio's avatar

Sure, i print {{ $company->image }} without problems.

But {!! $company->description !!} It is not rendered.

mstnorris's avatar

What version of Laravel are you using?

Sounds like you're using < 5.

You will need {{{ ... }}} in order to escape when using a version of Laravel prior to 5.

cloudstudio's avatar

Laravel 5 :)

"require": { "laravel/framework": "5.0.*",

mstnorris's avatar

Please can you post your full view file.

Also, just to double check, please run php artisan --version as you may have specified version 5, but if you were on version 4 before, and you haven't run a composer update then you won't be on version 5. I'm sure you are, but it's worth double checking before we move on.

cloudstudio's avatar

Okey

Laravel version : Laravel Framework version 5.0.32 Composer update done.

Full view :

@extends('front/layouts.default')
@section('content')

<section>
    <div id="nosotros" class="cont-general">
        <div class="bloque-fondos">
            @foreach($company as $compa)
                <div class="fondo-foto" style="background-image:url('{{ Config::get('app.url') }}/uploads/{{ $compa->background }}');background-size: cover;"></div>
            @endforeach
        </div>
        <div class="content">
            <div class="bloque-textos">
                    @foreach($company as $company)
                    <article class="texto">
                        <h2>{{ $company->title }}</h2>
                        @if(!empty($company->image))
                            <div class="imagen"><img src="{{ Config::get('app.url') }}/uploads/{{ $company->image }}" alt="{{ $company->titulo }}"/></div>
                        @endif
                        <div class="contenido">
                            {!! $company->description !!}
                        </div>
                    </article>
                    @endforeach
                </article>
            </div>
        </div>
    </div>
</section>

@stop
mstnorris's avatar

@cloudstudio are you getting an error?

What is $company->description and why does it need to be escaped? Can you provide a sample of what is contained within the description.

cloudstudio's avatar

Because i use wysiwyg editor in admin panel.

Example :

<h1>Title</h1>
<h3>Subtitle</h3>
<p>Lorem ipsum....></p>

mstnorris's avatar

@cloudstudio that is very strange. I'm thinking...

Instead of returning the view, can you dd($company->description)

phildawson's avatar

Has the value of description been set to {!! $company->description !!} by mistake and it's simply outputting that string? :D

mstnorris's avatar

Can you post your composer.json file so I can look over your third-party packages.

cloudstudio's avatar

Sure

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "laravel/framework": "5.0.*",
        "vinkla/translator": "~2.1",
        "barryvdh/laravel-debugbar": "~2.0",
        "intervention/image": "~2.2"
    },
    "require-dev": {
        "phpunit/phpunit": "~4.0",
        "phpspec/phpspec": "~2.1",
        "laracasts/generators": "~1.1",
        "fzaninotto/faker": "1.3.*@dev",
        "phpunit/phpunit": "4.0.*",
        "zizaco/entrust": "dev-laravel-5"
    },
    "autoload": {
        "classmap": [
            "database"
        ],
        "psr-4": {
            "Cloud\\": "app/"
        }
    },
    "autoload-dev": {
        "classmap": [
            "tests/TestCase.php"
        ]
    },
    "scripts": {
        "post-install-cmd": [
            "php artisan clear-compiled",
            "php artisan optimize"
        ],
        "post-update-cmd": [
            "php artisan clear-compiled",
            "php artisan optimize"
        ],
        "post-create-project-cmd": [
            "php -r \"copy('.env.example', '.env');\"",
            "php artisan key:generate"
        ]
    },
    "config": {
        "preferred-install": "dist"
    }
}
phildawson's avatar

So inside the blade template if you do

<?php echo $company->description; ?>

you get

<h1>Title</h1><h3>Subtitle</h3><p>Lorem ipsum....></p>

?

mstnorris's avatar

I have a sneaky suspicion it is to do with the Vinkla Translator package, can you paste the published config file for it.

Also on a side note, you will want to move barryvdh/laravel-debugbar to your dev dependencies. From the GitHub docs:

Note: Use the DebugBar only in development. It can slow the application down (because it has to gather data). So when experiencing slowness, try disabling some of the collectors.

1 like
cloudstudio's avatar

@mstnorris

<?php

/*
 * This file is part of Laravel Translator.
 *
 * (c) Vincent Klaiber <hello@vinkla.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

return [

    /*
    |--------------------------------------------------------------------------
    | Locale Eloquent Model
    |--------------------------------------------------------------------------
    |
    | This is the Eloquent model that handles what languages you support within
    | your project. Please provide the full namespaced path.
    |
    */

    'locale' => 'Cloud\Locale',

    /*
    |--------------------------------------------------------------------------
    | Locale Identifier Column
    |--------------------------------------------------------------------------
    |
    | Specify the column key that you want to compare with when fetching
    | translations trough the App::getLocale() method.
    |
    */

    'column' => 'language',

    /*
    |--------------------------------------------------------------------------
    | Fallback Support
    |--------------------------------------------------------------------------
    |
    | Set this to true if you want to fetch the default translation if the
    | current locale doesn't have any translated attributes yet. The default
    | fallback is fetched from app/config/app.php
    |
    */

    'fallback' => false,

];

cloudstudio's avatar

@mstnorris hard work I use it on all controllers and some models.

and if I change the tags? like version 4 what do you think?

phildawson's avatar

I would just temporarily comment out the service provider 'Vinkla\Translator\TranslatorServiceProvider' in config/app.php and check the output of {!! $company->description !!} again so it can be determined if it is that package causing the issue.

cloudstudio's avatar

Commented //'Vinkla\Translator\TranslatorServiceProvider',

Nothing happens.

Output : {!! $company->description !!}

lol

phildawson's avatar

So it isn't that, and the other packages are going to be fine.

To rule out it being the word description have you tried to temporarily modify the table so the column is called descriptionfoo and then output that.

{!! $company->descriptionfoo !!}
cloudstudio's avatar

Yes, if i try with other columns, like image, title... allways return {!! $company->title !!}

I dont have more ideas :(

i think i use php tags in blade template :/

phildawson's avatar
Level 26

So what you're saying is these work in outputting the parsed strings?

{{ $company->title }}
{{ $company->image }}
{{ $company->description }}

but these don't when trying to output the raw?

{!! $company->title !!}
{!! $company->image !!}
{!! $company->description !!}

If that is the case then the raw tags may have been changed? Try this line before outputting the view or simply search for setRawTags to see if it's being modified anywhere.

\Blade::setRawTags('{!!', '!!}');
cloudstudio's avatar

Works with \Blade::setRawTags('{!!', '!!}');

lol, why ? It is not defined by default?

pmall's avatar

Did you updated from L4.2 ? Something must have go wrong :)

Next

Please or to participate in this conversation.