nette / latte

☕ Latte: the safest & truly intuitive templates for PHP. Engine for those who want the most secure PHP sites.
https://latte.nette.org
Other
1.13k stars 109 forks source link

Add namespace loader #320

Open alexander-schranz opened 1 year ago

alexander-schranz commented 1 year ago

This introduce a namespace loader. This allows to use a namespace like app:: similar to Plates and Blade template engine.

Usage:

    $defaultLoader = new FileLoader(__DIR__ . '/templates');
    $emailLoader = new FileLoader(__DIR__ . '/emails');
    $someLoader = new FileLoader(__DIR__ . '/vendor/some/some/templates');
    $otherLoader = new StringLoader(['main' => 'othercontent']);

    $loader = new NamespaceLoader([
        '' => $defaultLoader,
        'email' => $emailLoader,
        'some' => $someLoader,
        'other' => $otherLoader,
    ]);

This way it is very flexible as we can use any loader again.

alexander-schranz commented 1 year ago

@dg looks like you rebased it. Do I need to change the target branch?

Edit: Oh my fault looks like the master was force pushed to another state. I will rebase my branch.

Crell commented 2 months ago

It looks like @dg has been rebasing this diligently for 2 years. I am also very interested in this feature (the thing I'm trying to do right now likely won't really work without it), as currently there seems to be no way to reference a layout that is not in the same directory as the template, or else have relative paths defined in the {layout} block (ew).

Is there something we users could do to help move this forward, or get attention on it?