pug-php / pug

Pug template engine for PHP
https://www.phug-lang.com
MIT License
391 stars 42 forks source link

Get the current compiler and path/filename from the callback of a custom filter #101

Closed rik43 closed 6 years ago

rik43 commented 7 years ago

in custom filter we need to get template path. for example, i make include-markdown filter and can support insert by relative paths. or insert images by relative paths. Compiler class contain $filename property, but protected.

example in custom filter usage:

public function __invoke(Filter $node, Compiler $compiler)
{
    $templateFilename = $compiler->getFilename();
}
kylekatarnls commented 7 years ago

No problem,

It seems relevant. Will do it soon.

kylekatarnls commented 7 years ago

You can now upgrade to 2.5.2 and use $compiler->getFilename().

Thanks,

rik43 commented 7 years ago

awesome! Thanks!

kylekatarnls commented 7 years ago

I re-open to consider how to make this feature compatible with pug-php version 3.

rik43 commented 7 years ago

first, check if someone is using it. I, do not use this library now.

kylekatarnls commented 6 years ago

Fixed by https://github.com/phug-php/compiler/releases/tag/0.5.15:

This is the new way to get the filename:

public function __invoke($source, $options, Compiler $compiler)
{
    $templateFilename = $compiler->getPath();
}