From 06b30130173b4674142ee891088956742e8f00d1 Mon Sep 17 00:00:00 2001 From: Madhur Jain <21112002mj@gmail.com> Date: Thu, 5 Mar 2026 17:52:21 +0530 Subject: [PATCH 1/5] feat: implemented blocks in cta section pattern --- templates/_macros/vf_cta-section.jinja | 66 ++++++++++++++++++++++---- 1 file changed, 57 insertions(+), 9 deletions(-) diff --git a/templates/_macros/vf_cta-section.jinja b/templates/_macros/vf_cta-section.jinja index 57314185e..62e2a2b3b 100644 --- a/templates/_macros/vf_cta-section.jinja +++ b/templates/_macros/vf_cta-section.jinja @@ -1,11 +1,15 @@ +{% from "_macros/shared/vf_cta-block.jinja" import vf_cta_block %} +{% from "_macros/shared/vf_description-block.jinja" import vf_description_block %} + # All Params # title_text: H2 title text # variant: variant for the cta section. Options are "default", "block". Default is "default". # layout: Layout type of cta section. Options are "100", "25-75". + # blocks: list of content blocks for the CTA section. Includes description and cta blocks. # All Slots - # description: Paragraph-style (one or more) content below the title. This slot is required for "cta-block-100" and "cta-block-25-75" layouts. - # cta: Call-to-action block with action links/buttons. This slot is required for "cta-block-100" and "cta-block-25-75" layouts. + # description (deprecated): Paragraph-style (one or more) content below the title. This slot is required for "cta-block-100" and "cta-block-25-75" layouts. + # cta (deprecated): Call-to-action block with action links/buttons. This slot is required for "cta-block-100" and "cta-block-25-75" layouts. # Variants: # default-100: Full-width CTA with title and link text @@ -14,6 +18,7 @@ # variant: default # layout: 100 # attrs: A dictionary of attributes to apply to the section element + # blocks: cta-block is required # Slots: # cta: The cta link - required @@ -23,6 +28,7 @@ # title_text: H2 title text - optional # variant: default # layout: 25-75 + # blocks: cta-block is required # Slots: # cta: The cta link - required @@ -32,6 +38,7 @@ # title_text: H2 title text - required # variant: block # layout: 100 + # blocks: cta-block is required # Slots: # description: Paragraph-style (one or more) content below the title - Optional @@ -42,31 +49,69 @@ # title_text: H2 title text - required # variant: block # layout: 25-75 + # blocks: cta-block is required # Slots: # description: Paragraph-style (one or more) content below the title - Optional # cta: Call-to-action block (required) -{%- macro vf_cta_section(title_text, variant='default', layout='100', caller=None, attrs={}) -%} +{%- macro vf_cta_section(title_text, variant='default', layout='100', caller=None, attrs={}, blocks=[]) -%} + + {%- set description_block = blocks | selectattr("type", "equalto", "description") | list | last | default(None) -%} + {%- set cta_block = blocks | selectattr("type", "equalto", "cta") | list | last | default(None) -%} + {% set description_content = caller('description') %} - {% set has_description = description_content|trim|length > 0 %} + {% set has_description = description_block or description_content|trim|length > 0 %} {% set cta_content = caller('cta') %} - {% set has_cta = cta_content|trim|length > 0 %} + {% set has_cta = cta_block or cta_content|trim|length > 0 %} + + {%- if cta_block -%} + {%- set cta_block_item = cta_block.get("item", {}) -%} + {%- set cta_block_type = cta_block_item.get("type","") | trim -%} + + {%- if cta_block_type == "html" -%} + {%- set cta_content = cta_block_item.get("content","") | trim -%} + {%- endif -%} + {%- endif -%} + + {%- if description_block -%} + {%- set description_block_item = description_block.get("item", {}) -%} + {%- endif -%} + {#- User can pass layout as "X-Y" or "X/Y" -#} {% set layout = layout | trim | replace('/', '-') %} + {% if layout not in ['100', '25-75'] %} {% set layout = "100" %} {% endif %} + {% set variant = variant | trim %} {% if variant not in ['default', 'block'] %} {% set variant = "default" %} {% endif %} + {%- macro _description_block() -%} - {% if has_description %}{{ description_content }}{% endif %} - {%- endmacro -%} + {%- if description_block -%} + {{ vf_description_block(type = description_block_item.get("type", ""), content = description_block_item.get("content","")) }} + {% elif has_description %} + {{ description_content }} + {% endif %} + {%- endmacro %} + {%- macro _cta_block() -%} - {% if has_cta -%}
The quick brown fox jumps over the lazy dog.
- {%- endif -%} - {%- if slot == 'cta' -%} - Action - Action - Lorem ipsum dolor sit amet › - {%- endif -%} - {% endcall -%} + {% call(slot) vf_cta_section( + title_text='The quick brown fox jumps over the lazy dog', + variant='block', + layout='25-75', + blocks=[ + { + "type": "description", + "item": { + "type": "text", + "content": "The quick brown fox jumps over the lazy dog." + } + }, + { + "type": "cta", + "item": { + "primary": { + "content_html": "Action", + "attrs": { + "href": "link-url", + "class": "optional-css-class" + } + }, + "secondaries": [ + { + "content_html": "Secondary action", + "attrs": { + "href": "link-url" + } + } + ], + "link": { + "content_html": "Lorem ipsum dolor sit amet ›", + "attrs": { + "href": "link-url" + } + } + } + } + ] + ) -%} + {% endcall -%} {% endblock %} diff --git a/templates/docs/examples/patterns/cta-section/block-full-width.html b/templates/docs/examples/patterns/cta-section/block-full-width.html index 2f865041f..804271d66 100644 --- a/templates/docs/examples/patterns/cta-section/block-full-width.html +++ b/templates/docs/examples/patterns/cta-section/block-full-width.html @@ -4,18 +4,45 @@ {% block standalone_css %}patterns_all{% endblock %} {% set is_paper = true %} {% block content %} - {% call(slot) vf_cta_section( - title_text='The quick brown fox jumps over the lazy dog', - variant='block', - layout='100' - ) -%} - {%- if slot == 'description' -%} -The quick brown fox jumps over the lazy dog.
- {%- endif -%} - {%- if slot == 'cta' -%} - Action - Action - Lorem ipsum dolor sit amet › - {%- endif -%} - {% endcall -%} + {% call(slot) vf_cta_section( + title_text='The quick brown fox jumps over the lazy dog', + variant='block', + layout='100', + blocks=[ + { + "type": "description", + "item": { + "type": "text", + "content": "The quick brown fox jumps over the lazy dog." + } + }, + { + "type": "cta", + "item": { + "primary": { + "content_html": "Action", + "attrs": { + "href": "link-url", + "class": "optional-css-class" + } + }, + "secondaries": [ + { + "content_html": "Action", + "attrs": { + "href": "link-url" + } + } + ], + "link": { + "content_html": "Lorem ipsum dolor sit amet ›", + "attrs": { + "href": "link-url" + } + } + } + } + ] + ) -%} + {% endcall -%} {% endblock %} diff --git a/templates/docs/examples/patterns/cta-section/cta-block.html b/templates/docs/examples/patterns/cta-section/cta-block.html new file mode 100644 index 000000000..1912183a8 --- /dev/null +++ b/templates/docs/examples/patterns/cta-section/cta-block.html @@ -0,0 +1,41 @@ +{% extends "_layouts/examples.html" %} +{% from "_macros/vf_cta-section.jinja" import vf_cta_section %} +{% block title %}CTA section / CTA block{% endblock %} +{% block standalone_css %}patterns_all{% endblock %} +{% set is_paper = true %} +{% block content %} + {% call(slot) vf_cta_section( + title_text='The quick brown fox jumps over the lazy dog', + variant='block', + layout='25-75', + blocks=[ + { + "type": "cta", + "item": { + "primary": { + "content_html": "Action", + "attrs": { + "href": "link-url", + "class": "optional-css-class" + } + }, + "secondaries": [ + { + "content_html": "Secondary action", + "attrs": { + "href": "link-url" + } + } + ], + "link": { + "content_html": "Lorem ipsum dolor sit amet ›", + "attrs": { + "href": "link-url" + } + } + } + } + ] + ) -%} + {% endcall -%} +{% endblock %} diff --git a/templates/docs/examples/patterns/cta-section/default-25-75-links-within-text.html b/templates/docs/examples/patterns/cta-section/default-25-75-links-within-text.html index 9f87b6ddb..e79c93274 100644 --- a/templates/docs/examples/patterns/cta-section/default-25-75-links-within-text.html +++ b/templates/docs/examples/patterns/cta-section/default-25-75-links-within-text.html @@ -4,14 +4,18 @@ {% block standalone_css %}patterns_all{% endblock %} {% set is_paper = true %} {% block content %} - {% call(slot) vf_cta_section( - variant='default', - layout='25/75', - ) -%} - {%- if slot == 'cta' -%} - For more information, read the docs -block variant with 25-75 layout to create
View example of the 25-75 split cta section with cta block
+## Blocks
+
+### Description
+
+Description blocks can be used to display elaborative text content.
+
+By default, the description contents are rendered within a `` tag, but you can also use `type:"html"` to render raw HTML +content. + +
+ +```json +{ + "type": "description", + "item": { + "type": "text" | "html", + "content": "Your content here" + } +} +``` + +- **`type`**: Either `"text"` (default) or `"html"`. Text content is wrapped in `` tags, HTML content is rendered as-is.
+- **`content`**: The text or HTML content to display.
+
+### CTA
+
+The CTA block allows you to include call-to-action elements within the section.
+You may either use `type:"html"` with `content:"