Support the ongoing development of Laravel.io →
Views Blade
Last updated 2 years ago.
0

But is it also possible to extend the parsing of {{"my dummy text"}}, so I can use that instead of @parse()? I can't get it to work because {{"my dummy text"}} seems to be parsed before my blade extensions are called.

The {{ "my dummy text" }} is parsed as a basic echo whatever is inside the {{ ? }}

You might be able to find the parse line and extend it, but it would likely be easier to modify what your wanting and use the extend.

What is it your trying to accomplish?

0

Thanks for the reply.

What I want to accomplish is that all texts between {{ }} are first passed to a parse function before the echo.

Example:

{{"[LINK name='test']this is a link[/LINK]"}}

Result:

<?php echo "<span data-link='test'>this is a link</span>"; ?>

I can accomplish this via the new @parse(), but I want to avoid this and use the standard {{ }}.

Last updated 9 years ago.
0

A few ideas,

To just use the {{ "LINK name='test'...}} I think you would need to extend the BladeCompiler class and overwrite the compilerRegularEchos and then add in the code to check for the [link] tag then do the magic to make it replace the text.

Or like you said, use the blade extend option and create a custom function, something like : @myLink("name","linktext"); which would return the compiled string.

Or you could make a helper class or facade and called it like {{ SomeHelperClass:makeMyLink("name","linktext"); }} the helper class would return the string which would then be echoed back on the template.

Or you could use a included template and just pass the vars to it which would then make the string text.

Hope that helps some

0

Thanks. I did overwrite the BladeCompiler and got what i needed. Code I used to overwrite:

use Illuminate\Support\ServiceProvider;
use Illuminate\View\Engines\CompilerEngine;

class MyBladeCompiler extends \Illuminate\View\Compilers\BladeCompiler
{
     //Overwrite functions of BladeCompiler
}

class ExtendBladeServiceProvider extends ServiceProvider {

    public function register()
    {
        $app = app();
		
        $resolver = $app['view']->getEngineResolver();

        $resolver->register('blade', function() use ($app)
        {
            $cache = $app['path.storage'].'/views';

            $compiler = new MyBladeCompiler($app['files'], $cache);

            return new CompilerEngine($compiler, $app['files']);
        });
    }
}
0

Sign in to participate in this thread!

Eventy

Your banner here too?

KevinM86 kevinm86 Joined 3 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.