Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block context #114

Open
jbmoelker opened this issue Jan 20, 2024 · 0 comments · May be fixed by #120
Open

Block context #114

jbmoelker opened this issue Jan 20, 2024 · 0 comments · May be fixed by #120

Comments

@jbmoelker
Copy link
Member

jbmoelker commented Jan 20, 2024

User story

As a developer,
I want to know the context of a Block,
so that I can use that for its configuration.

For example: when you know where an ImageBlock is on the page, you can configure its image loading strategy (instantly when on top, lazily when lower on the page). And similar behaviour for lazy embeds (#107), and native video element preload: auto|none (#33).

Possible solution

Right now, Blocks are registered in and included from src/blocks/Blocks.astro, like:

<SomeContentBlock 
  block={ dataFromCms }
/>

We could add a context like so:

<SomeContentBlock 
  block={ dataFromCms }
  context={{
    location: 'header|body|footer',
    index: 0...n,
  }}
/>

Page models have a bodyBlocks field, and could be extended with a headerBlocks and footerBlocks field in the future. This could then be passed in the context as location like in the example above.

This concept is based on discussion with @Siilwyn about Shopify: Announcing new Liquid features for better web performance:

New Liquid section properties
[...] We have three new properties for you (docs):

  • section.index - the 1-based index of the section within its contextual location
  • section.index0 - the 0-based index of the section within its contextual location
  • section.location - the section’s location (can also be thought of as the section’s context or scope)
@jbmoelker jbmoelker linked a pull request Jan 24, 2024 that will close this issue
8 tasks
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 a pull request may close this issue.

1 participant