Assigning an ID Attribute to Children of Posts-Template
-
Hello, I’m creating a carousel block that uses a custom variation of a query loop with an inner block of post template, which has an inner block of a custom block that renders the posts based on the context passed by the post template block.
This works perfectly fine to render the posts on the back-end and the front-end. However, for the sake of toggling a hidden state on inactive carousel panels I need a way to assign a unique ID attribute on each panel rendered by the post template.
Because the posts are rendered by the post template block, I cannot use the typical block-editor functions to select each rendered post because they aren’t rendered as blocks, the only block that’s rendered is core/post-template.
As a workaround, I created my own query loop block that fetches data from the Rest API, but this is not ideal because the data is only fetched and updated when users re-render the parent block on the back-end.
edit: I should note that using the context prop of postId will not work. Because I want to avoid users having to re-render the carousel block on the back-end to update attributes/data, the ID value passed to blocks rendered by post-template must be fixed, such as 0, 1, 2, 3, 4 when rendering 5 total blocks from post-template.
- You must be logged in to reply to this topic.