Support #8200
openQuestion: WText inline image without UnsafeXHTML ?
0%
Description
Hi All,
I am trying to insert into WText widget inlined image, like
<span style="display:inline-block;">
<img>
</img>
</span>
but it happens to work only with UnsafeXHTML
As long as data provided for the widget comes from various sources, i do want benefit from safe variant, avoiding dangerous scripts running.
Is there a way to make it in an alternative safe manner, staying simple at the same time (not writing own parser to insert layout widgets etc) ?
Or is there a chance img directive will be moved to safe side, just like span, and parsed dirrectly from the text ?
Updated by Korneel Dumon over 3 years ago
Hi Andrii,
I think you need WTemplate
, there you can put images in the text. Then you can use WTemplate::bindString
to bind any text that should be filtered.
Another way to add an image to a page is to use WImage
.
Updated by Andrii Zhuk over 3 years ago
Korneel Dumon wrote in #note-1:
Hi Andrii,
I think you need
WTemplate
, there you can put images in the text. Then you can useWTemplate::bindString
to bind any text that should be filtered.
Another way to add an image to a page is to useWImage
.
Thank you Korneel, WTemplate
+ WTemplate::bindWidget
(using WImage
as widget) did the trick.
Was a little bit stuck on thw way how template is created and operates. So for someone else:
- see https://www.webtoolkit.eu/widgets/layout/html-templates for example
- use
WTemplate::setTemplateText
to set template string (https://www.webtoolkit.eu/wt/doc/reference/html/classWt_1_1WTemplate.html) - use
WTemplate::bindString
orWTemplate::bindWidget
to insert your needed code or widget - the best thing about
WTemplate
is thatWTemplate::setTemplateText
is marked asTextFormat::XHTML
, but inserted parts may beTextFormat::UnsafeXHTML
, just what I needed