Skip to content

Can we have data-wp-html directive similar to data-wp-text for Interactivity API? #70531

@BhargavBhandari90

Description

@BhargavBhandari90

There is no way to render HTML using Directive?

When we use Interactivity API for block and if we want to display html content inside data-wp-each we can't display our html contnet using any directive.

In the below sample code, I want to render html for class="step-text"

Sample code:

<template data-wp-each--step="context.steps">
	<div class="step-card" data-wp-bind--data-index="context.step.index" data-wp-class--show="state.showStep">
		<div data-wp-text="context.step.step"></div>
		<div class="step-text" data-wp-text="context.step.description"></div>
	</div>
</template> 

What is your proposed solution?

We should have directive like data-wp-html

Activity

Bhumit9416

Bhumit9416 commented on Jul 17, 2025

@Bhumit9416

Hi! 👋
I totally agree with this proposal — the current data-wp-text directive only renders plain text, which escapes HTML, making it difficult to display rich formatted content such as bold text, links, or custom markup inside data-wp-each loops.

A data-wp-html directive (or similar) would solve this gap nicely. Some thoughts:

It should safely insert trusted HTML into the DOM, like innerHTML, but within a sandboxed or scoped context.

Perhaps it could follow a similar implementation pattern as dangerouslySetInnerHTML in React — with clear warnings or escapes when necessary.

It could optionally sanitize or allow developers to opt into raw HTML rendering (with a warning if needed).

I'd love to try a prototype or explore how this could be added to the existing directive system.
Let me know if this enhancement is being planned — I'd be happy to help or test a PR for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @BhargavBhandari90@t-hamano@Bhumit9416

        Issue actions

          Can we have `data-wp-html` directive similar to data-wp-text for Interactivity API? · Issue #70531 · WordPress/gutenberg