Skip to content

Example Blade extension from docs does not work #4770

@carcinocron

Description

@carcinocron

I already posted this here a month ago: http://laravel.io/forum/05-20-2014-example-blade-extension-from-docs-does-not-work

This triggers a fatal error

Blade::extend(function($view, $compiler)
{
    $pattern = $compiler->createMatcher('datetime');

    return preg_replace($pattern, '$1<?php echo $2->format('m/d/Y H:i'); ?>', $view);
});
syntax error, unexpected 'm' (T_STRING)

Obviously fixed by changing:

'$1<?php echo $2->format('m/d/Y H:i'); ?>'

to

'$1<?php echo $2->format(\'m/d/Y H:i\'); ?>'

But then:

<?php $c = Carbon::now(); ?>

<?php echo ($c)->format('m/d/Y H:i'); ?>
Symfony \ Component \ Debug \ Exception \ FatalErrorException
syntax error, unexpected '->' (T_OBJECT_OPERATOR), expecting ',' or ';'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions