Skip Navigation

[Resolved] Toolset Blocks Add custom classnames or data attribute to divs inside loop view

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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 1 reply, has 2 voices.

Last updated by Waqar 1 year, 1 month ago.

Assisted by: Waqar.

Author
Posts
#2661633
blocks.png
Screenshot 2023-11-07 110629.png

Hello,

I am testing out the 'Toolset Blocks' plugin, and have questions regarding the 'View Loop' block.

I have created a simple test view with toolset block view. On the front-end, looking at the devTool (the HTML structure), I see that it has generated a parent container/div for each post item, and the divs has these classnames:
"wp-block-toolset-views-view-template-block wpv-block-loop-item php-to-be-replaced-with-shortcode"

and the data attribute:
data-toolset-views-view-template-block="59ce0d027cb7c1f650e0dca66ce0d7ae"

(screenshot attached- highlighted in yellow)

Is there a way to customize the generated parent container/div?

I would like add a custom class name to the loop div that would have a dynamic post value, such as the post ID. So something like this:
class="wp-block-toolset-views-view-template-block wpv-block-loop-item php-to-be-replaced-with-shortcode loop-item-id-77"

In the example above, the custom classname is 'loop-item-id-77' , 77 is the dynamic value (the post ID).
Also, I have included a screenshot of the list view on how I've created this test view.

Is there a way to add a custom classname with a dynamic post value for each of the parent container inside the loop container?

Thank you!

#2661935
custom-class-example.png

Hi,

Thank you for contacting us and I'd be happy to assist.

While it is possible to include a static custom class in the 'View Loop' block ( example screenshot attached ), it doesn't accept a shortcode for a dynamic value.

Alternative, could be to either use a classic view where you have full control over the view's output or use custom script, that gets the Post ID value from each of the loop item and then add it as a class name on-the-fly, once the page has loaded.

regards,
Waqar