pug-php / pug

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

Dynamic mixins? #138

Closed Spone closed 7 years ago

Spone commented 7 years ago

I tried to use interpolation in mixin name, as allowed in Pug (see this issue https://github.com/pugjs/pug/issues/1282) but it does not seem to work with pug-php.

I encountered an issue with the following code:

mixin hit-article(data)
  = "hit-article works!"

mixin hit(type)
  .hit
    +#{'hit-' + type}

+hit('article')

I expected to get:

<div class="hit">hit-article works!</div>

But I actually get:

<div class="hit">+hit-article</div>

Will you support this feature?

kylekatarnls commented 7 years ago

Thanks, I plan it for version 3.0. Depending on my free time, maybe I could add it before. If you can, feel free to propose a pull-request.

kylekatarnls commented 7 years ago

Implemented, please upgrade to 2.6.0.

Spone commented 7 years ago

That was fast, thanks!

Spone commented 7 years ago

I updated to 2.6.0, but I have this error when I try to use dynamic mixins:

Notice: Undefined index: hit-article_mixin in pug.stream:// [...] Fatal error: Uncaught Error: Function name must be a string in pug.stream:// [...]

kylekatarnls commented 7 years ago

Undefined index: hit-article_mixin is not about dynamic mixins use. It means the declaration for the mixin is missing. Please show the mixin hit-article declaration and the call.

Spone commented 7 years ago

I did not change the default value for this option. I have other mixins with dashes - in the name and they work correctly.

kylekatarnls commented 7 years ago

Yes sorry, it was a bad interpretation, I removed my message. The dynamic mixin try to access hit-article, that seems right. Does the declaration exists?

kylekatarnls commented 7 years ago

As you can see, this unit test succeed: https://github.com/pug-php/pug/blob/master/tests/templates/mixins.dynamic.jade Can you provide a unit test to reproduce your bug?

Spone commented 7 years ago

The simple test case works for me. There is probably an issue somewhere else in my code.

I fixed my issue by enabling the 'pugjs' => true option.