I have a Custom Block type called HomeBlocks. This bundle has a paragraphs field which allows multiple paragraphs.
I then place (using Layout Builder) an instance of this block type on my home page (a node type called Landing Page). In the layout of the block type I have a View which lists some of the paragraphs added to that specific block. The view lists my paragraphs but lists all the paragraphs of that type. If I add a contextual filter for Parent ID to the view and set as Fixed with the value being the BlockID of the block which I placed on my home page; then it filters to only the ones added to that block. Perfect.
The question is then; how to dynamically set this contextual filter?
I can think of 2 approaches:
- Create a contextual filter plugin which passes the BlockID.
- Pass BlockID from the Layout to the View.
I looked at option 2 a while back and found some work being done to allow arguments to be passed back from LB; but it was only supporting static values (as opposed to tokens).
Option 1 seems pretty simple and I set that up. To start with I simply pass back the static ID value and this works as expected.
The missing piece here is how to get a list of blocks (of a certain type) which are placed on a specific node?
I tried doing this with a view and I can get a list of BlockIds of all the blocks of this type; but can't see how to filter to the the one used on the specific node.
If there will ever be only 1 instance of this block used on the site; then I can use my existing view (that lists the only block of this type). I am not concerned about having multiple versions of this block on a single page; but I am trying to accommodate that there could be multiple pages with this block added.