laravel/framework

[5.4] Blade: no way to setContentTags() anymore

denis-chmel opened this issue ยท 15 comments

  • Laravel Version: 5.4.8

Description:

@taylorotwell
It's problematic to migrate to 5.3 -> 5.4 when e.g we reserve {{ .. }} for angularJS, and <?php echo .. ?> for everything else. There seems to be no (simple) way anymore to override Blade tag syntax, after setContentTags(), setEscapedContentTags() were wiped in 5e394bb.

Steps To Reproduce:

class AppServiceProvider extends ServiceProvider
    public function register()
        \Blade::setContentTags('[%%', '%%]');
        \Blade::setEscapedContentTags('[-%%', '%%-]');
   }
}
> php artisan clear-compiled


  [Symfony\Component\Debug\Exception\FatalThrowableError]
  Call to undefined method Illuminate\View\Compilers\BladeCompiler::setContentTags()

It was removed yes, you can use @{{ }} to stop blade from compiling the tag.

Thanks, just was there a reason to add such regression?
There's nothing in commit message 5e394bb about this, so maybe just an overlook. Also there's no warning in Upgrade Guide:
https://laravel.com/docs/5.4/upgrade

This is kind of a significant change that shouldn't be in a "minor" version revision (5.3 -> 5.4) as it's a breaking change. I'd recommend holding off making a change of this magnitude until the next major version.

This is kind of a significant change that shouldn't be in a "minor" version revision (5.3 -> 5.4) as it's a breaking change. I'd recommend holding off making a change of this magnitude until the next major version.

Laravel minor versions are the same as semver major versions, and laravel patch releases are the same as semver minor versions.

It was removed because it's generally a really bad idea to use it. It makes using any Blade related packages essentially impossible since developers will not know which mark-up tags to use for Blade.

Thanks @taylorotwell.

While this particular change is not a big deal, your team is trying to decide for us what we shall stick to. It's hard to customize Laravel because of such hardcodes. Could you leave setter as "undocumented feature", mark it as @deprecated maybe?

/**
 * @deprecated Avoid using this method as other packages may stop working
 */
function setContentTags($value) {

The PHPStorm is highlighting calls of deprecated methods, so people will know that they're using those on their own risk. Please don't remove setter just because it may lead to a problem, we're not children to hide matches from :)

I have to agree with @denis-chmel on this. I totally understand your point that it shouldn't be used, I like the new way a lot better. Adding that was a great change. However It doesn't erase the fact that code using setContentTags already exists in nontrivial amounts (go do a code search). Continuing to support it keeps people productive, and adding the deprecated tag help people get the right idea for the future. We're all adults here.

@taylorotwell

Is there a way to drop blade in favour of a more flexible template engine eg twig? We have an app on 5.3 using client side AngJS 1 templates rendered from blade. We need to use both blade tpl syntax and angJs syntax, adding an @ before each angjs tpl var is excessive as the app has only about 20% variables from blade.

We are stuck on 5.3 now.

Is there a way to drop blade in favour of a more flexible template engine eg twig?

Yes, you can use whatever templating engine you want.

So use other peoples code in favour of clean own code...
Isn't that just a financial decision and not a 'good' or 'really bad' idea decision?

If anybody need it badly I've solved it for me via a local patch (switches to <<< and >>> tags)

composer.json

     "scripts": {
         "post-install-cmd": [
            .... 
            "patch_blade_tags.sh",
         ],
     },

patch_blade_tags.sh:

#!/usr/bin/env bash
set -e

IN_FILE=vendor/laravel/framework/src/Illuminate/View/Compilers/BladeCompiler.php
sed -i "s|protected \$contentTags.*|protected \$contentTags = ['<<<', '>>>'];|" $IN_FILE
sed -i "s|protected \$escapedTags.*|protected \$escapedTags = ['<<<<', '>>>>'];|" $IN_FILE

This is really a BAD idea!

The bad idea is to violate open/closed principle, @icaife ;)

This should really be part of the upgrade documentation from 5.3 to 5.4. This is a breaking change for many teams and should be at least highlighted.