ResolveKey with conditional blocks in the XML?
Added by Zach Motsinger over 9 years ago
I have an instance of Wt::WMessageResourceBundle that contains paths to XML files. When I call the function "resolveKey" on this, I cannot find message tags that are encapsulated in condition blocks (used for Wt::WTemplate).
For instance, in my XML I have this:
${<cond-true>}
<message id="my-message">
<div class="style">Hello!</div>
</message>
${</cond-true>
Then, when I call the following code:
bool resolveKey(std::string& result)
{
Wt::WMessageResourceBundle* resourceBundle = new Wt::WMessageResourceBundle();
resourceBundle->use(Wt::WApplication::instance()->appRoot() + "myXMLName");
return (resourceBundle->resolveKey("my-message", result));
}
The function returns false even though the ${} tags are being resolved to true. If I remove these tags, the code executes as expected and returns true.
Is there any way to explicitly tell the Wt::WMessageResourceBundle to render everything inside the conditional tags? Or perhaps even ignore them entirely? There don't seem to be a lot of options for dealing with this sort of thing. Is there a better way that Wt::WTemplate and Wt::WMessageResourceBundle were intended to work in tandem?
Thanks a bunch.
Replies (1)
RE: ResolveKey with conditional blocks in the XML? - Added by Stefan Arndt over 9 years ago
I could be wrong, but the conditionals can only be used inside(!) the message tag and then enabled/disabeld from within a WTemplate. What your are trying to do should (but does not) lead to a parse error, imho.
<message id="my-message">
${<cond-true>}
<div class="style">Hello-True!</div>
${</cond-true>
</message>
(Sidenote, in case your example is not only an example: I would not use a resolveKey-function as you did above, since each time a key is resolved, you create a new resource bundle. Furthermore the code leaks memory since you do not delete the resource bundle. Have a look at the resource bundle of WApplication.)
See also: http://www.webtoolkit.eu/wt/doc/reference/html/classWt_1_1WTemplate.html#details