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

Hi, it seems like the identifier test is reserved in some way, as it always return blank. Also, Laravel comes with some helpers for Blade Extensions which makes the job abit easier. See Extending Blade.

Eg:

<?php
Blade::extend(function($view, $compiler)
{
    $pattern = $compiler->createMatcher('totime');

    return preg_replace($pattern, '$1<?php echo strtotime($2); ?>', $view);
});

Would return the time whenever using @totime('now').

Last updated 2 years ago.
0

Thanks alot, works for me in this case... but whats the best way to implement kind of buisnesslogic to Blade::extend()?

This seems not so elegant to me as it may could be.... ;-)

<?php
Blade::extend(function($view, $compiler) {
    $pattern = $compiler->createMatcher("weCheck");
    return preg_replace($pattern, '$1<?php '
            . '$we_timestamp = strtotime($2); '
            . '$we_expired = strtotime("+1 day", $we_timestamp);'
            . 'if($we_expired < time()){'
            . 'echo "red";'
            . '}'
            . '?>', $view);
});
Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

slein87 slein87 Joined 27 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.