You are here

simplenews-newsletter-body.html.twig in Simplenews 3.x

Default theme implementation to format the simplenews newsletter body.

Copy this file in your theme directory to create a custom themed body. Rename it to override it. Available templates: simplenews-newsletter-body--[newsletter_id].html.twig simplenews-newsletter-body--[view mode].html.twig simplenews-newsletter-body--[newsletter_id]--[view mode].html.twig See README.txt for more details.

Available variables:

  • build: Render array. Use {{ build }} to print it.
  • node: object(Drupal\node\Entity\Node) The node entity with limited access to object properties and methods.

    • Methods: Only "getter" methods (method names starting with "get", "has", or "is") and a few common methods such as "id" and "label" are available. {{ node.getTitle }} : the Node title ( == {{ title }} ) Calling other methods (such as node.delete) will result in an exception.
    • Properties: field values can be accessed as follows: {{ node.body.value | raw }} : text of body field
  • newsletter: object(Drupal\simplenews\Entity\Newsletter) {{ newsletter.from_name }}: string {{ newsletter.subject }}: string
  • title: Node title
  • view_mode: The active display view mode of the node
  • key: email key [node|test]
  • format: newsletter format [plain|html]
  • simplenews_subscriber: object(Drupal\simplenews\Entity\Subscriber) The subscriber for which the newsletter is built. {{ simplenews_subscriber.getMail }}: string: subscriber's email address Note that depending on the used caching strategy, the generated body might be used for multiple subscribers. If you created personalized newsletters and can't use tokens for that, make sure to disable caching or write a custom caching strategy implemention.

File

templates/simplenews-newsletter-body.html.twig
View source
  1. {#
  2. /**
  3. * @file
  4. * Default theme implementation to format the simplenews newsletter body.
  5. *
  6. * Copy this file in your theme directory to create a custom themed body.
  7. * Rename it to override it. Available templates:
  8. * simplenews-newsletter-body--[newsletter_id].html.twig
  9. * simplenews-newsletter-body--[view mode].html.twig
  10. * simplenews-newsletter-body--[newsletter_id]--[view mode].html.twig
  11. * See README.txt for more details.
  12. *
  13. * Available variables:
  14. * - build: Render array. Use {{ build }} to print it.
  15. * - node: object(Drupal\node\Entity\Node)
  16. * The node entity with limited access to object properties and methods.
  17. * * Methods: Only "getter" methods (method names starting with "get", "has", or "is")
  18. * and a few common methods such as "id" and "label" are available.
  19. * {{ node.getTitle }} : the Node title ( == {{ title }} )
  20. * Calling other methods (such as node.delete) will result in an exception.
  21. * * Properties: field values can be accessed as follows:
  22. * {{ node.body.value | raw }} : text of body field
  23. * - newsletter: object(Drupal\simplenews\Entity\Newsletter)
  24. * {{ newsletter.from_name }}: string
  25. * {{ newsletter.subject }}: string
  26. * - title: Node title
  27. * - view_mode: The active display view mode of the node
  28. * - key: email key [node|test]
  29. * - format: newsletter format [plain|html]
  30. * - simplenews_subscriber: object(Drupal\simplenews\Entity\Subscriber)
  31. * The subscriber for which the newsletter is built.
  32. * {{ simplenews_subscriber.getMail }}: string: subscriber's email address
  33. * Note that depending on the used caching strategy, the generated body might
  34. * be used for multiple subscribers. If you created personalized newsletters
  35. * and can't use tokens for that, make sure to disable caching or write a
  36. * custom caching strategy implemention.
  37. *
  38. * @see template_preprocess_simplenews_newsletter_body()
  39. */
  40. #}
  41. <h2>{{ title }}</h2>
  42. {{ build }}
  43. {% if not opt_out_hidden %}
  44. {% if format == 'html' %}
  45. <p class="newsletter-footer"><a
  46. href="[simplenews-subscriber:unsubscribe-url]">{{ unsubscribe_text }}</a>
  47. </p>
  48. {% else %}
  49. -- {{ unsubscribe_text }} : [simplenews-subscriber:unsubscribe-url]
  50. {% endif %}
  51. {% endif %}
  52. {% if key == 'test' %}
  53. - - - {{ test_message }} - - -
  54. {% endif %}