Project

General

Profile

External template

Added by Michael Backus over 10 years ago

I'm using a template to layout my webpage as follows:

string strTemplate("<table><tr><td>${filteredFrame}</td><td>${sliderHueMin}</td></tr><tr><td>${frame}</td></tr></table>");
WTemplate *t = new WTemplate(strTemplate,root());

I'd like to import the html from a separate file instead of writing it directly into my cpp program. Is this possible? If so, how do I go about doing so?


Replies (4)

RE: External template - Added by Michael Backus over 10 years ago

I did a little more searching and came across a similar post: [[[http://redmine.webtoolkit.eu/boards/2/topics/6556?r=6557#message-6557]]]

As a consequence, I created the following cpTemplate.xml file:

<messages><message id="control-panel"><table><tr><td>${filteredFrame}</td><td>${sliderHueMin}</td></tr><tr><td>${frame}</td></tr></table></message></messages>

I then modified by program as follows:

ControlPanel::ControlPanel(const WEnvironment& env)
    : WApplication(env)
{
    messageResourceBundle().use("/home/debian/robot/cpTemplate");
    WTemplate *t = new WTemplate(Wt::WString::tr("control-panel"));

    //Rest of my code
}

Unfortunately, although it compiles, when I run the app it hangs and never displays anything. When I hit refresh on the browser, it hangs again, and then crashes.

RE: External template - Added by Wim Dumon over 10 years ago

Hello Michael,

This is e.g. demonstrated in the example 'form', in the directory examples/form.

What is the exception you get in a debugger at the moment of the crash? What does the stack trace look like?

Best regards,

Wim.

RE: External template - Added by Michael Backus over 10 years ago

I finally figured this out last night. I was missing root() at the end of the message bundle. Here are the lines of code that I ended up using:

ControlPanel::ControlPanel(const WEnvironment& env)
    : WApplication(env)
{
    messageResourceBundle().use(appRoot() + "cpTemplate");
    WTemplate *t = new WTemplate(Wt::WString::tr("control-panel"),root());

    //Rest of code
}

RE: External template - Added by Michael Backus over 10 years ago

I think there would be fewer questions regarding this in the forum if those two lines of code were mentioned on this page: http://www.webtoolkit.eu/widgets/layout/html-templates

    (1-4/4)