Project

General

Profile

Template engine is missed?

Added by Alir3z4 _ over 12 years ago

Wt really need a template engine for god sake !

coz without template engine all of the work going messy.

maybe coz i worked with those framework like django *andrails*, but come'on

also communicating withdatabases is really worse in cpp files, but with template engine like those pythonic samples out there really wt going to be sweet as possible.

i like to know your opinion guys.

tnx


Replies (7)

RE: Template engine is missed? - Added by Wim Dumon over 12 years ago

Did you discover the class Wt::WTemplate (simple template engine) and the Wt::Dbo namespace?

BR,

Wim.

RE: Template engine is missed? - Added by Alir3z4 _ over 12 years ago

I used them both, But i mean Separate code from the view (put in html template files)

is there any plan on it ?

RE: Template engine is missed? - Added by Koen Deforche over 12 years ago

Hey Alizera,

I believe we are not understanding well what you are looking for then.

With WTemplate, you are putting the "view" in an HTML template file?

Actually, WTemplate is a pure static template, in the sense that it does not contain any logic at all (in contrast with many other template languages) ?

Perhaps you want the template to be "automatically" populated with data from a database, and not using calls to bind() ?

I've used neither django or rails, so, what are we missing? Can you provide some sample code of what you would like to see work with Wt ?

Regards,

koen

RE: Template engine is missed? - Added by Alir3z4 _ over 12 years ago

Thank for quick reply.

For instance in django for html rendering or better to say everything user shoulda see going to html file and also with really useful template engine language developer can playing variables in html file without playing on programming coding stuff.

what i saying is this:

https://docs.djangoproject.com/en/dev/topics/templates/

this is what wee can do with a list

{% for story in story_list %}
<h2>
  <a href="{{ story.get_absolute_url }}">
    {{ story.headline|upper }}
  </a>
</h2>
<p>{{ story.tease|truncatewords:"100" }}</p>
{% endfor %}

tnx

RE: Template engine is missed? - Added by Koen Deforche over 12 years ago

Hey,

So, this actually looks a lot like PHP, doesn't it --- mixing code with HTML ?

To implement this in C, you are missing reflexion, but even then, I consider it bad habit to add programming details to a view, or even invent a new programming/scripting language there.

With Wt, you would do this using two templates:

story_list:

 ${stories}
 <p>${story.tease}</p>

story:

<h2>
  <a href="${story.absolute_url}">
    ${story.headline}
  </a>
</h2>

And in C code:

 WContainerWidget *stories = new WContainerWidget();
 for (...) {
   WTemplate *story = new WTemplate(tr("story"), stories);
   story->bindString("story.absolute_url", ...);
   story->bindString("story.headline", ...);
 }

 WTemplate *story_list = new WTemplate(tr("story_list"));
 story_list->bindString("story.tease", ...");
 story_list->bindWidget("stories", stories);

The benefit is that you would probably specialize the story widget, and add behavior to it to interact with it.

Consider for example the blog example, where each comment is a widget with which you can interact.

Regards,

koen

RE: Template engine is missed? - Added by Alir3z4 _ over 12 years ago

Hey Koen

Maybe i don't look around in example as well, but in blog example i didn't saw anything like your way to doing that.

Coz in all of the examples playing with output is done in cpp files, as you said mixing code with html isn't good idea, so html with cpp codes is okay?

So as you mention i shoulda put story, story_list in html files or in a cpp files... ?

I think Wt shoulda be more that just GUI tools for web programing, coz with such great classes is shouldn't be!

I can mention to cppCMS to handle template files in separate files, and benefit is developer can focus on application logic and all of output, html game kept out!

Thank you so much for your well explaining Koen.

RE: Template engine is missed? - Added by con abs over 12 years ago

but in blog example i didn't saw anything like your way to doing that.

But in the blog example I can find WTemplate s, which are something like koen's way doing that.

So as you mention i shoulda put story, story_list in html files or in a cpp files... ?

In separate xml file(s).

to handle template files in separate files,

You can handle template files in separate files in Wt as you wish. One thing to mention here: Wt's template file does not have any code.

    (1-7/7)