How can I print a variable in the node template?

For example, if it's a variable of content, we can print it with the following code.

{{ content.field_name }}

If I have a {{ counter }} variable, how do I display it with Twig?

  • 1
    Welcome to Drupal Answers! Your question is not clear: You already know to use {{ counter }}, so what exactly don't you understand? – kiamlaluno Nov 23 '16 at 9:41
  • Where did counter come from? – No Sssweat Nov 24 '16 at 1:04

If it's a variable that came from a hook_preprocess_node, you can just print it in your twig template as you wrote it in your example:

{{ variable_name }}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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