pug-php / pug

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

Is there any way or any possible to support symbol `|` as inline mixin? #123

Closed Riant closed 7 years ago

Riant commented 7 years ago

We can not call mixin inline for now in Pug or pug-php, so I think if we can make some kind of code like below works like mixin.

time(data-date=$data['date']|dateFormat('Y/M/j'))= $data['date']|dateFormat('Y-M-j')

The symbol | will be translated as dateFormat($data['date'], 'Y/M/j').

I hope my idea is clear. Thanks.

kylekatarnls commented 7 years ago

Yes we are thinking about a Twig adapter that would handle all Twig syntaxes in expressions. But remember this code has already a meaning in PHP: $data['date']|dateFormat('Y/M/j') is $data['date'] Bitwise Or dateFormat('Y/M/j') so use the | as in Twig or Angular 1 seems not to be a good option as it breaks PHP native feature. Moreover what is the benefit of $data['date']|dateFormat('Y/M/j') over dateFormat($data['date'], 'Y/M/j'), seems not to me harder to read. And it means developers have both syntaxes to know.

Last thing, Pug responsability is the HTML representation. In the next version on which we hard working: https://github.com/phug-php will allow you to do any transformation on each expression and so plug another language. But we will not provide again magic translations. We will recommend to use raw PHP in your expressions. If you need to imports templates from a pugjs project, we will provide js-phpize as expression handler. But for any other language, the user will be on his own.

Riant commented 7 years ago

Got it, thanks.