You are here

paragraph--default.html.twig in Varbase Bootstrap Paragraphs 8.7

Default theme implementation to display a paragraph in Bootstrap Paragraphs.

Available variables:

  • paragraph: Full paragraph entity.

    • id: The paragraph ID.
    • bundle: The type of the paragraph, for example, "image" or "text".
    • authorid: The user ID of the paragraph author.
    • createdtime: Formatted creation date. Preprocess functions can reformat it by calling format_date() with the desired parameters on $variables['paragraph']->getCreatedTime().
  • content: All paragraph items. Use {{ content }} to print them all, or print a subset such as {{ content.field_example }}. Use {{ content|without('field_example') }} to temporarily suppress the printing of a given child element.
  • attributes: HTML attributes for the containing element. The attributes.class element may contain one or more of the following classes:

    • paragraphs: The current template type (also known as a "theming hook").
    • paragraphs--type-[type]: The current paragraphs type. For example, if the paragraph is an "Image" it would result in "paragraphs--type--image". Note that the machine name will often be in a short form of the human readable label.
    • paragraphs--view-mode--[view_mode]: The View Mode of the paragraph; for example, a preview would result in: "paragraphs--view-mode--preview", and default: "paragraphs--view-mode--default".
  • view_mode: View mode; for example, "preview" or "full".
  • logged_in: Flag for authenticated user status. Will be true when the current user is a logged-in member.
  • is_admin: Flag for admin user status. Will be true when the current user is an administrator.

File

templates/paragraph--default.html.twig
View source
  1. {#
  2. /**
  3. * @file
  4. * Default theme implementation to display a paragraph in Bootstrap Paragraphs.
  5. *
  6. * Available variables:
  7. * - paragraph: Full paragraph entity.
  8. * - id: The paragraph ID.
  9. * - bundle: The type of the paragraph, for example, "image" or "text".
  10. * - authorid: The user ID of the paragraph author.
  11. * - createdtime: Formatted creation date. Preprocess functions can
  12. * reformat it by calling format_date() with the desired parameters on
  13. * $variables['paragraph']->getCreatedTime().
  14. * - content: All paragraph items. Use {{ content }} to print them all,
  15. * or print a subset such as {{ content.field_example }}. Use
  16. * {{ content|without('field_example') }} to temporarily suppress the printing
  17. * of a given child element.
  18. * - attributes: HTML attributes for the containing element.
  19. * The attributes.class element may contain one or more of the following
  20. * classes:
  21. * - paragraphs: The current template type (also known as a "theming hook").
  22. * - paragraphs--type-[type]: The current paragraphs type. For example, if the paragraph is an
  23. * "Image" it would result in "paragraphs--type--image". Note that the machine
  24. * name will often be in a short form of the human readable label.
  25. * - paragraphs--view-mode--[view_mode]: The View Mode of the paragraph; for example, a
  26. * preview would result in: "paragraphs--view-mode--preview", and
  27. * default: "paragraphs--view-mode--default".
  28. * - view_mode: View mode; for example, "preview" or "full".
  29. * - logged_in: Flag for authenticated user status. Will be true when the
  30. * current user is a logged-in member.
  31. * - is_admin: Flag for admin user status. Will be true when the current user
  32. * is an administrator.
  33. *
  34. * @see template_preprocess_paragraph()
  35. *
  36. * @ingroup themeable
  37. */
  38. #}
  39. {{ attach_library('varbase_bootstrap_paragraphs/vbp-default') }}
  40. {{ attach_library('varbase_bootstrap_paragraphs/vbp-colors') }}
  41. {# Background color. #}
  42. {% if content.bp_background|render %}
  43. {% set layout_background = content.bp_background['#items'].getString() %}
  44. {% set layout_background_classes = [ layout_background ] %}
  45. {% endif %}
  46. {# The template default set classes. #}
  47. {%
  48. set classes = [
  49. 'paragraph',
  50. 'paragraph--type--' ~ paragraph.bundle|clean_class,
  51. view_mode ? 'paragraph--view-mode--' ~ view_mode|clean_class,
  52. ]
  53. %}
  54. {# Merges Background color with classes. #}
  55. {% set background_field = content.bp_background|render %}
  56. {% if background_field %}
  57. {% set classes = classes|merge(layout_background_classes) %}
  58. {% endif %}
  59. {# No container by default. #}
  60. {% set add_container = false %}
  61. {# If there is BG image it's always edge to edge #}
  62. {% if (VBP.background_image.url or content.bp_background|render) %}
  63. {% set attributes = attributes.addClass('bg-edge2edge') %}
  64. {% set add_container = true %}
  65. {% endif %}
  66. {# If gutter option were selected. #}
  67. {% if VBP.bp_gutter.value %}
  68. {% set add_container = true %}
  69. {% endif %}
  70. {% if VBP.background_image.url %}
  71. {% set attributes = attributes.addClass('background-style') %}
  72. {% endif %}
  73. {# Merges Background color with classes. #}
  74. {% set background_field = content.bp_background|render %}
  75. {% if background_field %}
  76. {% set classes = classes|merge(layout_background_classes) %}
  77. {% endif %}
  78. {# Sets Unique ID for paragraph from Paragraph ID. #}
  79. {% set paragraph_id = 'vbp-' ~ paragraph.id.value %}
  80. {# Sets paragraph title for paragraph. #}
  81. {% set paragraph_title = content.bp_title[0]['#context']['value']|render %}
  82. {# Sets paragraph title status for paragraph. #}
  83. {% set paragraph_title_status = true %}
  84. {% if VBP.bp_title_status.value %}
  85. {% set paragraph_title_status = false %}
  86. {% endif %}
  87. {# Add custom paragraph CSS class(es). #}
  88. {% if VBP.bp_classes.value %}
  89. {% set striped_custom_classes = VBP.bp_classes.value|striptags|lower %}
  90. {% set split_custom_classes = striped_custom_classes|split(' ') %}
  91. {% for custom_class in split_custom_classes %}
  92. {% set clened_custom_class = [ custom_class|clean_class ] %}
  93. {% set classes = classes|merge(clened_custom_class) %}
  94. {% endfor %}
  95. {% endif %}
  96. {# Prints div with classes, and content without Width and Background. #}
  97. <div{{ attributes.addClass(classes).setAttribute('id', paragraph_id) }} {% if VBP.background_image.url %} style="background-image:url({{- VBP.background_image.url -}});" {% endif %}>
  98. {% if add_container %}<div class="container">{% endif %}
  99. <div class="row">
  100. <div class="{{- VBP.bp_width.value -}}">
  101. {% if paragraph_title and paragraph_title_status %}<h2 class="text-center">{% spaceless %}{{- paragraph_title|striptags -}}{% endspaceless %}</h2>{% endif %}
  102. {% set attributes = attributes.removeClass('bg-edge2edge') %}
  103. {{ title_suffix }}
  104. {{ content|without('bp_title', 'bp_title_status', 'bp_width', 'bp_background', 'bp_image_field', 'bp_classes', 'bp_gutter') }}
  105. </div>
  106. </div>
  107. {% if add_container %}</div>{% endif %}
  108. </div>