alexanoid
alexanoid

Reputation: 25832

Vaadin 23 how to add multilanguage meta description to the page

I know how to add meta page title in Vaadin 23 - I use HasDynamicTitle and thus can provide different titles at different languages (depends on the user locale) for different pages. But how to do the same meta description? I need to be able to provide different meta tags for different pages

Upvotes: 1

Views: 247

Answers (1)

From what I can see there is no convenience API for dynamically changing the meta description. Looking at how HasDynamicTitle is implemented, we can see that it effectively delegates to UiInternals.setTitle, which just schedules a Javascript call of document.title = $0.

If you want to do the same for the meta description, you can schedule a JS call during the initialization of your view to modify the content of the meta tag:

this.executeJs(
  "document.querySelector('meta[name=\"description\"]').setAttribute('content', $0);",
  getLocalizedDescription()
);

Note that this only modifies the meta description after the page has loaded, and does not affect the content of the meta tag that is in the initial HTML document. If you want to modify that, let's say for SEO purposes or generating link previews, then you need to look into using IndexHtmlRequestListener. The same would apply for the title, the method you are using at the moment only changes the title after loading the page.

Upvotes: 2

Related Questions