You are here

paragraph--text-and-image.html.twig in Varbase Bootstrap Paragraphs 8.6

Varbase Bootstrap Paragraphs template for displaying a Text and Image layout.

File

modules/vbp_text_and_image/templates/paragraph--text-and-image.html.twig
View source
  1. {#
  2. /**
  3. * @file
  4. * Varbase Bootstrap Paragraphs template for displaying a Text and Image layout.
  5. *
  6. * @see template_preprocess_paragraph()
  7. *
  8. * @ingroup themeable
  9. */
  10. #}
  11. {{ attach_library('varbase_bootstrap_paragraphs/vbp-default') }}
  12. {{ attach_library('varbase_bootstrap_paragraphs/vbp-colors') }}
  13. {{ attach_library('vbp_text_and_image/vbp_text_and_image_default') }}
  14. {# Background color. #}
  15. {% if content.bp_background|render %}
  16. {% set layout_background = content.bp_background['#items'].getString() %}
  17. {% set layout_background_classes = [ layout_background ] %}
  18. {% endif %}
  19. {# Renders Column Style field. #}
  20. {# Sets class name from values in database. #}
  21. {% if content.text_and_image_style|render %}
  22. {% set fields_style = content.text_and_image_style['#items'].getString() %}
  23. {% set col_1 = [
  24. 'paragraph--style--50-50' == fields_style ? 'col-lg-6',
  25. 'paragraph--style--75-25' == fields_style ? 'col-lg-9',
  26. 'paragraph--style--66-33' == fields_style ? 'col-lg-8',
  27. 'paragraph--style--25-75' == fields_style ? 'col-lg-3',
  28. 'paragraph--style--33-66' == fields_style ? 'col-lg-4',
  29. ]
  30. %}
  31. {% set col_2 = [
  32. 'paragraph--style--50-50' == fields_style ? 'col-lg-6',
  33. 'paragraph--style--75-25' == fields_style ? 'col-lg-3',
  34. 'paragraph--style--66-33' == fields_style ? 'col-lg-4',
  35. 'paragraph--style--25-75' == fields_style ? 'col-lg-9',
  36. 'paragraph--style--33-66' == fields_style ? 'col-lg-8',
  37. ]
  38. %}
  39. {% endif %}
  40. {# The template default set classes. #}
  41. {%
  42. set classes = [
  43. 'paragraph',
  44. 'paragraph--type--' ~ paragraph.bundle|clean_class,
  45. view_mode ? 'paragraph--view-mode--' ~ view_mode|clean_class,
  46. ]
  47. %}
  48. {# Merges Background color with classes. #}
  49. {% set background_field = content.bp_background|render %}
  50. {% if background_field %}
  51. {% set classes = classes|merge(layout_background_classes) %}
  52. {% endif %}
  53. {# No container by default. #}
  54. {% set add_container = false %}
  55. {# If there is BG image it's always edge to edge #}
  56. {% if (VBP.background_image.url or content.bp_background|render) %}
  57. {% set attributes = attributes.addClass('bg-edge2edge') %}
  58. {% set add_container = true %}
  59. {% endif %}
  60. {# If gutter option were selected. #}
  61. {% if VBP.bp_gutter.value %}
  62. {% set add_container = true %}
  63. {% endif %}
  64. {% if VBP.background_image.url %}
  65. {% set attributes = attributes.addClass('background-style') %}
  66. {% endif %}
  67. {# Sets Unique ID for paragraph from Paragraph ID. #}
  68. {% set paragraph_id = 'vbp-' ~ paragraph.id.value %}
  69. {# Sets paragraph title for paragraph. #}
  70. {% set paragraph_title = content.bp_title|render %}
  71. {# Sets paragraph title status for paragraph. #}
  72. {% set paragraph_title_status = true %}
  73. {% if VBP.bp_title_status.value %}
  74. {% set paragraph_title_status = false %}
  75. {% endif %}
  76. {# Add custom paragraph CSS class(es). #}
  77. {% if VBP.bp_classes.value %}
  78. {% set striped_custom_classes = VBP.bp_classes.value|striptags|lower %}
  79. {% set split_custom_classes = striped_custom_classes|split(' ') %}
  80. {% for custom_class in split_custom_classes %}
  81. {% set clened_custom_class = [ custom_class|clean_class ] %}
  82. {% set classes = classes|merge(clened_custom_class) %}
  83. {% endfor %}
  84. {% endif %}
  85. {# Prints div with classes, and content. #}
  86. <div{{ attributes.addClass(classes).setAttribute('id', paragraph_id) }} {% if VBP.background_image.url %} style="background-image:url({{- VBP.background_image.url -}});" {% endif %}>
  87. {% if add_container %}<div class="container">{% endif %}
  88. <div class="row">
  89. <div class="{{- VBP.bp_width.value -}}">
  90. {% if paragraph_title and paragraph_title_status %}<h2 class="text-center">{{- paragraph_title -}}</h2>{% endif %}
  91. {# Check the Image position field. #}
  92. {% set align = content.field_image_position['#items'].getString() %}
  93. {% if align == "left"%}
  94. {% set img_align = 'align2left' %}
  95. {% set txt_align = 'align2right' %}
  96. {% else %}
  97. {% set img_align = 'align2right' %}
  98. {% set txt_align = 'align2left' %}
  99. {% endif %}
  100. {% set image_attr = create_attribute() %}
  101. {% set image_attr = image_attr.addClass('no-spacing').addClass(img_align) %}
  102. {# Set text field attributes. #}
  103. {% set text_attr = create_attribute() %}
  104. {% set text_attr = text_attr.addClass(txt_align).addClass('wrapper') %}
  105. <div{{ image_attr.addClass(col_1) }}>{{ content.field_image|render }}</div>
  106. <div{{ text_attr.addClass(col_2) }}>{{ content.field_text_content|render }}</div>
  107. </div>
  108. </div>
  109. {% if add_container %}</div>{% endif %}
  110. </div>