Html element id
Added by Jagadees S over 7 years ago
Hi,
I created a WTemplate and called following function.
t->setTemplateText(\"
${myheader}
\");
everything is fine except the id. The id is missing in the output.
What i have to do to get a result like this:
....
Thanks,
Jagadees
Replies (4)
RE: Html element id - Added by Bruce Toll over 7 years ago
Hi,
Wt manages the id attribute specially. You may want to look at the documentation for setId() https://www.webtoolkit.eu/wt/doc/reference/html/classWt_1_1WWebWidget.html#a31bbe256124dd34461800c9dd5558b0b and setObjectName() https://www.webtoolkit.eu/wt/doc/reference/html/classWt_1_1WWidget.html#ac91d9820f78cce58ce9f0a9b62ace8ef.
RE: Html element id - Added by Jagadees S over 7 years ago
Thanks Bruce.
When tried setId(), it created another div over the header:
...
Will it have any effect SEO or HTML standards?
RE: Html element id - Added by Bruce Toll over 7 years ago
Hi,
I have not tested this, but you should be able to set a custom tag for WTemplate, such as "header", by calling setHtmlTagName(), see: https://www.webtoolkit.eu/wt/doc/reference/html/classWt_1_1WWebWidget.html#adf6034e0e715138cae479eae6e324ce6.
You should then be able to set the WTemplate's class with setStyleClass("site-header") and set the role attribute with setAttributeValue("role", "banner"). Of course, the contents of your WTemplate text will need to be adjusted accordingly.
RE: Html element id - Added by Jagadees S over 7 years ago
Thanks Bruce.
I found another solution, as implemented in wt-home example.
call messageResourceBundle().use(appRoot() + "home", false); where home is the resource xml file.
in the xml file create a message with required template.
${neritam-header}
and when creating the WTemplate, pass the id of the message like:
WTemplate *t = new WTemplate(WString::tr("template"), root());
Now its creating exactly what i want.
As you said id is special in wt. but at the time of creation if we can give a unique id, then it will use that id.
Anyway, thanks Bruce.
Regards,
Jagadees.