Dashboard > RIFE > ... > Templates > Bidirectional template engine
RIFE Log In | Sign Up   View a printable version of the current page.
Bidirectional template engine


Added by Geert Bevin, last edited by Geert Bevin on May 22, 2004
Labels: 
(None)

I've been thinking for a while about how to describe RIFE's template engine to people that are used to 99% of the ones that are out there (JSP, PHP, Velocity, Webmacro, Tea, ...). Almost all template engines start out with a desire to seperate design from logic, they allow users to push or pull values into the template and then they get stuck. Design is far more complex than setting a couple of values, so they start providing simple logical constructs and loops, maybe even variables, blocks and scopes, functions to reuse code, etc etc ... and in the end run incorporate an entire language (JSP) or create a new one (PHP). All this is based on the assumption that the logic provides data to the design which is then decorated and rendered from within the template. Imho, a fundamental last step is missing which creates an overly complex model to try to simulate it.

When data has been integrated into a design, a template engine should allow the logic to retrieve the result and use the concrete version of the templated layout for real output and manipulation. This means that together with incorporating data, a template engine should also provide results and thus be able to work in a bidirectional fashion instead of the limited common unidirectional approach.

All of a sudden the template engine then becomes extremely simple, no need to integrate any kind of logical constructs or loops, the same logic that provided the data is able to select or repeat results easily. It can extract and combine them and if the template engine is powerful enough, use it as a scratchpad to assemble all the pieces of the layout in an efficient manner. All the required information is already available in the logic. You also don't have to worry anymore about just how much logic bleeds into a template. The entire template becomes totally language independent and designer-friendly.

I /think/ I really like the sound of this idea.

Is there any chance you could give a little example? Showing perhaps just a little mini-template then a code-snippet which populates/manipulates it as you describe?

Then I'd be able to tell if what I think you are suggesting is what you actually /are/ suggesting .

Posted by Paul Mitchell-Gears at Jan 28, 2005 15:52 | Permalink

Hi Paul,

This is how we implemented it in RIFE (you can find many other examples in this wiki). For instance, an XML template:

<list id="[!V 'id'/]" name="[!V 'name'/]" count="[!V 'count'/]">
    <description><![CDATA[<!--V 'description'--><!--/V-->]]></description>
    <!--V 'entries'--><!--/V-->
    <!--B 'entry'--><entry id="[!V 'entry_id'/]" name="[!V 'entry_name'/]" done="[!V 'entry_done'/]" priority="[!V 'entry_priority'/]"/><!--/B-->
</list>

and some code that uses it

Template t = getXmlTemplate("getlist");
t.setBean(list);

// create its entry elements
ContentQueryManager<Entry> entry_manager = getEntryQueryManager();
for (Entry entry : entry_manager.restore(entry_manager.getRestoreQuery()
                    .fields(Entry.class)
                    .where("listid", "=", list.getId())
                    .orderBy("priority"))) {
    t.setBean(entry, "entry_");
    t.appendBlock("entries", "entry");
}
		
print(t);
Posted by Geert Bevin at Jan 31, 2005 12:03 | Permalink

I like the sound of it too, assuming that Rife's data validation
is 100% integrated. The design decision to leave logic constructs
out of templates was a good one, and makes this proposal possible.
And it would generalize to XML, not just (X)HTML, and this too
would be quite welcome.

Will it tho end up duplicating a lot of XForms ?
(That is a question, not a criticism.)

BTW can you break up the 4th line in the example ?
It really forces the browser to be unreadably wide.

Posted by Fred Baube at Feb 03, 2005 12:05 | Permalink

Sadly confluence doesn't allow editing of comments!!!

Posted by Geert Bevin at Feb 04, 2005 00:03 | Permalink


Are you enjoying Confluence? Please consider purchasing it today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.2.1a Build:#515 May 19, 2006) - Bug/feature request - Contact Administrators