How to import static html into a layout in Vaadin 23 ?

I wanted to import a static html into a layout like this:

@HtmlImport("/html/privacy.html") // static content
public class PrivacyPolicyStaticPageLayout extends VerticalLayout{

}

But I use Vaadin 23 and there is no HtmlImport available.

How to import static html into a layout in Vaadin 23 ?

What’s your use case in importing static html?

It is just a privacy page static html content.
I have the HTML page created separately and I wanted to include it in a layout. I will be adding this layout to a dialog window.

The annotation is not used for this - you need to use “new Html(String)” - additionally make sure only one root level element is present

I have the HTML file itself, not the string content

You have to read the content and supply it to Vaadin

Html content = new Html(htmlContentAsString);
privacyPolicyStaticPageLayout.add(content);

is this right @quirky-zebra ?

yes

cool, thanks

additionally make sure only one root level element is present
@quirky-zebra
It seems like I get the error Caused by: java.lang.IllegalArgumentException: HTML must contain exactly one top level element (ignoring text nodes). Found 3 elements with the tag names link, link, div

These tags: link & div can be anywhere in the body and can be allowed to have multiples of them as per HTML rule. Don’t know why it is still complaining it :frowning_with_open_mouth:

Well that’s a rule for the Html component, nothing related to HTML Standard - just wrap all your content in a div and you are good to go

alright

I remember I have asked the same question in the past, but I missed to recall your answer. Can you share how to do this if you dont mind?

What do you mean exactly?

how to wrap html content in div when the html content is available as string ?

“div” + string + “”

thanks, I get it now.

What about an iframe without borders?