Skip to content

Conversation

@34638a
Copy link
Contributor

@34638a 34638a commented Feb 7, 2025

Proposal for flag to disable default div wrapping behaviour for region handlebars object when the injected content is or is not present. This flag is a modifier is proposed for the purpose of allowing post render processes to recognise the non-existence of content and act accordingly, without additional processing requirements in handlebars or on client.

For example, with the flag, CSS can be constructed with a parent container to dynamically reframe the region container and adjust accordingly all on client without JS. In the below example screenshot, you will be able to see how the content appears when the implied action based off the CSS is to not display the child-5 region because the content is empty.

Context, anything within the template html tag below represents data created within the current theme editor for a given region: (note only regions child-1 to child-3 have content provided by the editor utility)

<template for-region="child-1">
<p>This will show up - 1</p>
</template>

<template for-region="child-2">
<p>This will show up - 2</p>
</template>

<template for-region="child-3">
<p>This will show up - 3</p>
</template>

Template

<div id="parent" class="flex flex-row border divide-x *:p-4">
    {{region name="child-1" unwrapped=true}}
    {{region name="child-2" unwrapped=false}}
    {{region name="child-3" unwrapped=true}}
    {{region name="child-4" unwrapped=true}}
    {{region name="child-5"}}
</div>

Rendered Output

<div id="parent" class="flex flex-row border divide-x *:p-4">
    <p>This will show up - 1</p>
    <div data-content-region="child-2">
        <p>This will show up - 2</p>
    </div>
    <p>This will show up - 3</p>
    <div data-content-region="child-5"></div>
</div>

image


cc @bigcommerce/storefront-team

Added proposal parameters for a variance in the return state of the region block helper.

`empty`: When the `empty` flag is truthy, if there is no content currently available for the named region; then return a empty string instead of the normal div wrapper.

`raw`: When the `raw` flag is truthy, omit the normal div wrapper when returning the region content.
@34638a 34638a marked this pull request as draft April 1, 2025 13:27
@34638a 34638a changed the title Update region.js - Proposal for flags empty and raw feat: region.js - Proposal for flags empty and raw May 8, 2025
… preserved. Add Test Cases for new unwrapped state.
@34638a 34638a changed the title feat: region.js - Proposal for flags empty and raw feat: region.js - Proposal for flag unwrapped accepting boolean truthy input May 8, 2025
@34638a 34638a marked this pull request as ready for review May 8, 2025 09:54
@34638a
Copy link
Contributor Author

34638a commented May 8, 2025

Hi @jairo-bc

Please enjoy another PR for consideration.

  • Jordan

@jairo-bc jairo-bc requested a review from bc-evan-johnson May 13, 2025 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant