Skip Navigation

[Escalated to 2nd Tier] Toolset Blocks and InnerBlocks

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 3 replies, has 2 voices.

Last updated by Nigel 7 months, 1 week ago.

Assisted by: Nigel.

Author
Posts
#2689088

Tell us what you are trying to do?
Want to add a block to a Toolset View in the View Loop and be able to access the ID of the instance within the loop. So get the ID of the current item within the loop

Is there any documentation that you are following?
Can't find any

Is there a similar example that we can see?

What is the link to your site?
Nothing to show as I am trying to figure out how to use.

I was looking at moving away from short codes, and creating a custom block that I could use within the View Loop, toolset-views/view-template-block. Since it has the ability to add InnerBlocks, I wanted to gain access to the current Item's ID, but not sure if you are exposing it. I can't locate any providesContext nor any general block config, so not sure what all you have available.

#2689434

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi there

You can output the post ID of the current item in the loop readily enough, with the Single Field block, and the attributes of that block include the ID as its content, but where they get the ID is via the proprietary dynamic sources system. I'm not sure how accessible that is to 3rd party developers, I'll have to ask and get back to you.

I would note that if you can set a block attribute with the ID in your custom block from the PHP context, then you should be able to get the ID from the global $post object, which is updated to the current item in the loop for each iteration.

#2689474

I created a block and when I add the block to the View Loop, the post ID that I am getting is for the page itself and not the View Loop ID. I am using a render_callback to output the template for the block. The block's context is set to use post_id already, but as I mentioned this is coming back as the page ID and not the post ID from the loop.

#2689920

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Sorry, I haven't forgotten you, but the person best placed to suggest a solution is away Easter week, so I likely won't have a suggestion until next week.

I tested this myself and confirm that the global $post object in this context refers to the page hosting the View, not to the current item in the View loop output.