1

In Drupal 8 I have a custom comment type and when I use the default core comment.html.twig to render the comments then variables like 'new_indicator_timestamp' and 'parent' get rendered as expected. But if I switch to using a custom layout (via layout_plugin and display suite) and copy across the relevant twig template code for those core comment preprocess variables into my own custom layout then they don't work.

What do I need to do to ensure that the comment.module template_preprocess_comment() variables are available to my custom comment layout?

1 Answer 1

0

Probably the twig changed, layout modules usually bring their own templates. You have to check which templates are used. To find this out use twig debug:

https://www.drupal.org/node/1903374

After you found the right twig you have to use the corresponding preprocess hook, which you find in the comments of the twig template.

2
  • I already have twig debugging turned on and have confirmed that the custom twig template I created is the one that's being used, so that's not the issue here. D8 core comments template variables are defined in comment.module template_preprocess_comment(). The issue is that these core variables aren't available in my custom template when applied to comments and I don't understand why. Surely if these variables are defined in the core module file (rather than a specific theme) then they should be available to any template that is used for comments?
    – inteja
    Commented Mar 22, 2016 at 10:20
  • No, the variables are only available in one template. See the second part of my answer.
    – 4uk4
    Commented Mar 22, 2016 at 10:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.