New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Blade cannot work properly, does not support custom directives/conditions #197
Comments
Hi. Blade::fromString($string, $translations, [
'facade' => Illuminate\Support\Facades\Blade::class
]); So, in the code: public static function fromString($string, Translations $translations, array $options = [])
{
if (empty($options['facade']) {
$cachePath = empty($options['cachePath']) ? sys_get_temp_dir() : $options['cachePath'];
$bladeCompiler = new BladeCompiler(new Filesystem(), $cachePath);
$string = $bladeCompiler->compileString($string);
} else {
$string = $options['facade']::compileString($string);
}
PhpCode::fromString($string, $translations, $options);
} What do you think? Do you like to work in a pull request? |
Yes, I like this option. I've created pull request, hoping we don't need tests for this, or?... But good idea will be highlight this option somewhere in docs for others who want correct exporting translates from directives. |
Yep, docs needs to be improved, not only for blade, but all other extractors/generators. But this is a different issue. Thanks for your contribution! |
Hello,
thank you for you awesome package. I have som updates/fixes to your blade compiler.
If your application does have custom directives/conditions, your compiler does not work properly.
version: v4.6.1
Reproduction of error:
AppServiceProvider.app
In this provider we register our custom directive.
layout.blade.php
My blade template with one working title and one buggy title... (Our application has custom directives for seo purposes...)
Solution:
Problem is in your blade extractor, where you are initializing new
Illuminate\View\Compilers\BladeCompiler
instance, instead of using existing facadeIlluminate\Support\Facades\Blade
which has registered all blade directives/conditions. When you initialize new BladeCompiler instance, then all custom directives binded into facade are missing. In this case your compiled template will not be properly compiled as in regular laravel response.Solution number 1.
You can just simple use Facade for compiling blade template. Here is updated your blade compiler.
Solutions number 2
But I am not sure, why you are using this blade compiler instead of using facade. Maybe better solution for some users who is using Blade without laravel will be this. ( Maybe blade without laravel is 💩 :)), so we do not need this solutions. )
The text was updated successfully, but these errors were encountered: