Skip to content

Object access in Runtime::lookupValue #18

@eliashaeussler

Description

@eliashaeussler

As you know, we use this library as base for our TYPO3 handlebars extension. While this works quite well (thanks again for all your efforts! ❤️), we repeatedly run into a limitation with the current implementation.

It's quite common in TYPO3 to pass objects to templates and later access properties and/or methods. Imagine something like this:

final readonly class Foo
{
    public function __construct(
        public string $bar,
        private string $boo = '',
    ) {}

    public function getBoo(): string
    {
        return $this->boo;
    }
}

$foo = new Foo('bar');

$template = <<<HBS
Bar: {{foo.bar}}
Boo: {{foo.boo}}
HBS;

$template = \DevTheorem\Handlebars\Handlebars::compile($template);
$result = $template(['foo' => $foo]);

In this particular example, we cannot access neither the bar property nor the boo property (through getBoo method). I understand that this contradicts the original Handlebars.js implementation and I don't ask for an explicit support for this specific use-case. But do you see any possibilities in providing a dedicated hook (or similar) in order for us to provide a specific implementation for lookups (as addition to the existing Runtime::lookupValue method)?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions