You are here

paragraph--bp-image.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--bp-image.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. {{ attach_library('varbase_bootstrap_paragraphs/vbp-image') }}
  42. {# Background color. #}
  43. {% if content.bp_background|render %}
  44. {% set layout_background = content.bp_background['#items'].getString() %}
  45. {% set layout_background_classes = [ layout_background ] %}
  46. {% endif %}
  47. {# The template default set classes. #}
  48. {%
  49. set classes = [
  50. 'paragraph',
  51. 'paragraph--type--' ~ paragraph.bundle|clean_class,
  52. view_mode ? 'paragraph--view-mode--' ~ view_mode|clean_class
  53. ]
  54. %}
  55. {# Wrapper classes. #}
  56. {% set wrapper_attribute = create_attribute() %}
  57. {# No container by default. #}
  58. {% set add_container = false %}
  59. {# If there is background it's always edge to edge #}
  60. {% if (content.bp_background|render) %}
  61. {% set attributes = attributes.addClass('bg-edge2edge') %}
  62. {% set add_container = true %}
  63. {% endif %}
  64. {# If gutter option were selected. #}
  65. {% if VBP.bp_gutter.value %}
  66. {% set add_container = true %}
  67. {% endif %}
  68. {# Sets Unique ID for paragraph from Paragraph ID. #}
  69. {% set paragraph_id = 'vbp-' ~ paragraph.id.value %}
  70. {# Sets paragraph title for paragraph. #}
  71. {% set paragraph_title = content.bp_title[0]['#context']['value']|render %}
  72. {# Sets paragraph title status for paragraph. #}
  73. {% set paragraph_title_status = true %}
  74. {% if VBP.bp_title_status.value %}
  75. {% set paragraph_title_status = false %}
  76. {% endif %}
  77. {# Add custom paragraph CSS class(es). #}
  78. {% if VBP.bp_classes.value %}
  79. {% set striped_custom_classes = VBP.bp_classes.value|striptags|lower %}
  80. {% set split_custom_classes = striped_custom_classes|split(' ') %}
  81. {% for custom_class in split_custom_classes %}
  82. {% set clened_custom_class = [ custom_class|clean_class ] %}
  83. {% set classes = classes|merge(clened_custom_class) %}
  84. {% endfor %}
  85. {% endif %}
  86. {# Prints div with classes, and content without Width and Background. #}
  87. <div{{ attributes.addClass(classes).addClass(layout_background_classes).setAttribute('id', paragraph_id) }}>
  88. {% if add_container %}<div class="container">{% endif %}
  89. <div class="row">
  90. <div class="{{- VBP.bp_width.value -}}">
  91. {% if paragraph_title and paragraph_title_status %}<h2 class="text-center">{% spaceless %}{{- paragraph_title|striptags -}}{% endspaceless %}</h2>{% endif %}
  92. {% if content.bp_link|render is not empty %}
  93. <a href="{{ content.bp_link.0['#url'] }}">
  94. {% endif %}
  95. {{ content|without('bp_title', 'bp_title_status', 'bp_title_status', 'bp_width', 'bp_background', 'bp_link', 'bp_classes', 'bp_gutter') }}
  96. {% if content.bp_link|render is not empty %}
  97. </a>
  98. {% endif %}
  99. </div>
  100. </div>
  101. {% if add_container %}</div>{% endif %}
  102. </div>