KDF HTML Templates

From KallestadWiki

Jump to: navigation, search

Contents

Overview

HTML Templates are meant to provide a clear separation of code execution and presentation layout. As publication systems have matured over the past several years, this kind of separation always seems to be a goal, but is rarely truly achieved. Because this is a ground level goal for KDF, the separation should be clear enough that most applications developed with the framework can benefit from clear separation.

Template Syntax

The templating syntax mirrors that of the HTML::Template CPAN module available for Perl. Capabilities for handling this syntax will be ported over to other development platforms for end user simplicity.

KDF will manage HTML::Template functionality within it's simplest form - that is to say that variable replacement is the primary function of KDF Templating and managing of expressions, looping structures, etc. should not be expected to have long term support. Looping might stick around because of the need to repeat rows in most applications, but the inclusion of programmatic structures within HTML templates runs converse to the objective of a clear separation of presentation and logical workflow.

Variable replacement

Within HTML Templates, anything that matches the following syntax will be replaced appropriately:

<TMPL_VAR NAME="PARAMETER_NAME">

Where PARAMETER_NAME is the key in the output hash.

A word on LOOPS

HTML::Template LOOP constructs do not allow for the use of parent object variable output from within the loop. I've given much thought to adding support specifically within KDF in order to make this happen, but the more I think about it the more it does not make sense. There are performance and security concerns that keep popping up that prevent me from doing so (they are fairly harmless for low traffic situations, but still...). If you want to make use of - say a username within a message loop, add the username to the message array hash.

Nested Templates

Templates can be simple single objects that are populated with variables, or they could be more complex structures designed to be reused in various situations.

Consider your regular run of the mill discussion forum - the posts are surrounded by their own templates, repeated over and over again, but populated with different data. The section of posts is surrounded by a container describing the thread. The thread is wrapped in a container describing the forum, and so on and so forth until you get to a basic wrapper that contains the header and footer information.

In the KDF, a master template would contain references to all of the internally nested templates that would need to be built out. Child templates are passed master variables only when they are defined to receive those variables.

More on Nested Templates


Template Performance

High Traffic Templates should be compiled and cached at startup.

The Basic KDF Application Framework Template

The KDF Environment is meant to host rich applications. Part of hosting these rich applications requires that abstract and rich application objects can be arbitrarily included. Those objects can have javascript dependencies, and where javascript dependencies exist, you must include references to that javascript code somewhere in your HTML document.

For this reason, I've provided a basic HTML Template that can be used as a base to work from that includes the necessary hooks for javascript rich application objects.

Base KDF Application Template

Kallestad Development Framework Topics

Personal tools