Project

General

Profile

Rendering a view

Added by Alexandre Bencz over 4 years ago

Hi!

I'm implementing a test web-site using the template system, so, in my template I have the HTML for the menu, footer and so on... and, in the middle of this HTML I want to render the content, something like this:

<!-- menu -->
<!-- code for the menu -->

${content}

<!-- footer -->
<!-- code for the footer -->

So, I want to know how is the best way to handle this... each button on menu will redirect to some view that should be rendered on the "content" tag of template


Replies (3)

RE: Rendering a view - Added by Ockert van Schalkwyk over 4 years ago

I also would like to know what the best way to do this is. Currently I bind a WContainerWidget to ${content} and call clear() on it then repopulate it.

RE: Rendering a view - Added by Marcelo Antunes over 4 years ago

You also can do the following:

- having one template with menu, footer and so on with a placeholder for content

  • bind a template (with the content) in the first template (like you bind a container or another widget)

RE: Rendering a view - Added by Roel Standaert over 4 years ago

Usually, the way to do that would indeed be to bind a widget there, like a WContainerWidget, another WTemplate, or often a WStackedWidget. You can also directly put the class on the div for that widget in the template with ${content class="main"} instead of:

<div class="main">
${content}
</div>

When using templates with Wt, you'll usually have a template for the general structure of the page, and a template for each subcomponent, or even for each subcomponent of that, maybe with some uses of WMenu and WStackedWidget in there, too.

You probably don't want to constantly rebind text or widgets in a large template, because that would require the entire template to be rerendered. Wt will put aside any bound widgets so it doesn't need to rerender those, but the template text will be replaced.

    (1-3/3)