templates/pages/_blocks/snippet_block.html.twig line 1

Open in your IDE?
  1. {% if view.snippet is defined and view.snippet is not empty %}
  2. {% set loadedSnippet = sulu_snippet_load(view.snippet.uuid).content|replace_translate_variables %}
  3. {% set snippetTemplate = view.snippet.template %}
  4. {# ========================================================================
  5. CONFIGURATION DES SNIPPETS - Pattern-driven
  6. ======================================================================== #}
  7. {# Variable par défaut pour éviter les erreurs #}
  8. {% set detailsPageObject = detailsPageObject is defined ? detailsPageObject : null %}
  9. {# Fonction pour convertir snake_case en camelCase #}
  10. {% set snakeToCamel = snippetTemplate|replace({'_': ' '})|title|replace({' ': ''}) %}
  11. {% set snakeToCamel = (snakeToCamel|slice(0, 1)|lower) ~ (snakeToCamel|slice(1)) %}
  12. {% set globalSnippetId = 'snippet-body-' ~ random() %}
  13. {# Configuration par défaut (pattern) #}
  14. {% set defaultConfig = {
  15. 'path': '/_snippets/' ~ snippetTemplate ~ '.html.twig',
  16. 'context': {
  17. (snakeToCamel): loadedSnippet,
  18. 'showSectionSettings': content.showSectionSettings|default(true),
  19. 'sectionSettings': content|default({}),
  20. 'globalSnippetId': globalSnippetId
  21. }
  22. } %}
  23. {# ========================================================================
  24. EXCEPTIONS - Seulement les cas qui ne suivent pas le pattern
  25. ======================================================================== #}
  26. {% set snippetConfig = {
  27. 'general_card': {
  28. 'path': loadedSnippet.model is defined
  29. ? '/pages/_includes/cards/general_cards/general_card_' ~ loadedSnippet.model ~ '.html.twig'
  30. : '/pages/_includes/cards/general_cards/general_card_default.html.twig',
  31. 'context': {'card': loadedSnippet},
  32. 'wrapper': 'GeneralCards'
  33. },
  34. 'list_card': {
  35. 'path': loadedSnippet.model is defined
  36. ? '/pages/_includes/cards/list_cards/list_card_' ~ loadedSnippet.model ~ '.html.twig'
  37. : '/pages/_includes/cards/list_cards/list_card_default.html.twig',
  38. 'context': {'card': loadedSnippet},
  39. 'wrapper': loadedSnippet.model is defined ? 'ListCards ' ~ loadedSnippet.model : 'ListCards',
  40. 'container': true
  41. },
  42. 'product_list_card': {
  43. 'path': '/pages/_includes/cards/product_list_cards/product_list_card_standard.html.twig',
  44. 'context': {'list': loadedSnippet}
  45. },
  46. 'legal_texts': {
  47. 'path': 'pages/_snippets/_legal_texts.html.twig',
  48. 'context': {'legalText': loadedSnippet}
  49. },
  50. 'category_legal_texts': {
  51. 'path': 'pages/_snippets/_category_legal_text.html.twig',
  52. 'context': {'detailsPageObject': detailsPageObject, 'category': loadedSnippet},
  53. 'condition': detailsPageObject is not null and detailsPageObject['@type'] is defined and detailsPageObject['@type'] is same as('Company')
  54. },
  55. 'banner': {
  56. 'path': 'pages/_snippets/_banner.html.twig',
  57. 'context': {'bannerContent': loadedSnippet, 'object': detailsPageObject is defined ? detailsPageObject : {}}
  58. },
  59. 'text_and_image': {
  60. 'path': 'pages/_snippets/_text_and_image.html.twig',
  61. 'context': {'textAndImageContent': loadedSnippet}
  62. },
  63. 'text_and_image_widerow': {
  64. 'path': 'pages/_snippets/_text_and_image_widerow.html.twig',
  65. 'context': {'textAndImageContent': loadedSnippet}
  66. },
  67. 'content_card': {
  68. 'path': '/pages/_includes/cards/content_cards.html.twig',
  69. 'context': {'snippet': loadedSnippet}
  70. },
  71. 'benefits_company': {
  72. 'path': 'pages/_includes/company/_benefits_company.html.twig',
  73. 'context': {'benefits': loadedSnippet}
  74. },
  75. 'banner_seo': {
  76. 'context': {'bannerSEO': loadedSnippet}
  77. },
  78. 'destinations': {
  79. 'context': {'destinationsSnippet': loadedSnippet}
  80. },
  81. 'pictogram_and_text_and_link_assembly': {
  82. 'context': {'pictogramAndTextAndLinkAssembly': loadedSnippet}
  83. },
  84. 'compagnies_partenaires': {
  85. 'context': {'partenaires': loadedSnippet}
  86. }
  87. } %}
  88. {# ========================================================================
  89. RENDU DU SNIPPET - Pattern par défaut + exceptions
  90. ======================================================================== #}
  91. {# Utiliser la config exceptionnelle ou le pattern par défaut #}
  92. {% set config = snippetConfig[snippetTemplate] is defined
  93. ? defaultConfig|merge(snippetConfig[snippetTemplate])
  94. : defaultConfig %}
  95. {% set shouldRender = config.condition is not defined or config.condition %}
  96. {% if shouldRender %}
  97. {% if config.wrapper is defined %}
  98. <section id="{{ globalSnippetId }}" class="snippet-body {{ config.wrapper }}" style="margin-top: {{ marginTopBlock|default('0px') }}">
  99. {% if content.showSectionSettings|default(true) %}
  100. {% include '_snippets/sections/general_section_settings.html.twig' with {
  101. 'content': content,
  102. 'id': globalSnippetId
  103. } %}
  104. {% endif %}
  105. {% if config.container is defined and config.container %}
  106. <div class="container">
  107. {% include config.path with config.context %}
  108. </div>
  109. {% else %}
  110. {% include config.path with config.context %}
  111. {% endif %}
  112. </section>
  113. {% else %}
  114. <section id="{{ globalSnippetId }}" class="snippet-body" style="margin-top: {{ marginTopBlock|default('0px') }}">
  115. {% if content.showSectionSettings|default(true) %}
  116. {% include '_snippets/sections/general_section_settings.html.twig' with {
  117. 'content': content,
  118. 'id': globalSnippetId
  119. } %}
  120. {% endif %}
  121. {% include config.path with config.context %}
  122. </section>
  123. {% endif %}
  124. {% endif %}
  125. {% endif %}