Closed alessandro-fazzi closed 3 years ago
Indeed, the sure thing is RENDER
event is too late: the whole mixin is yet replaced by HTML/PHP code at this point. Hooking the node event is a possible solution, but if you can you should try first to make it done using pug code so the magic is not hidden to the next developer working in the template:
Does something prevent you to rename your post()
mixin into an other name and add a middle mixin:
mixin validated_post($postID)
post
header
h3!= link_to(get_the_title($postID), get_permalink($postID))
content!= get_the_excerpt($postID)
mixin post($unvalidatedPostID)
+validated_post(get_validated_post_id($unvalidatedPostID))
+post(1)
@kylekatarnls I'd sum up saying you convinced me :) I've opted for a more explicit approach similar to the one you proposed.
Thanks for your always kind support.
Hello,
I am trying to achieve to read parameters passed to a
mixin
before it is rendered. My will would be to validate parameters with custom implementation. E.g:I've tried intercepting the rendering process with
\Phug\RendererEvent::RENDER
but it seems really wrong. I've tried using\Phug\CompilerEvent::NODE
but it seems like I could get only the declared params with their default value ($postID
with anull
value given my example). I can't get how I could intercept the value1
I'm passing to the mixin and inject my custom valdation.Thanks in advance for your time.