lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On Jan 20, 2009, at 6:33 PM, Tobias Markmann wrote:

If not luarocks then it must be cosmo. I wonder if someone knows a different
template engine which is pure lua.

If you like it, hmmm, rather minimalist, Nanoki does have a rather straightforward template mechanism:

Here is an usage example from Nanoki to displays the page index:

<br />
    <li><a href='[v:href]' title='[v:name]'>[v:name]</a>[v:tag]</li>

Note the [v:variable] place holders for, well, variable substitutions and the [t:template][/t:template] for sub-templates. There are no other constructs.

Here is part of the code populating the template above:
local aTemplate = Template[ 'WikiIndexService.txt' ]
for aContent, aURL in anIterator do
    local aNameTemplate = aTemplate[ 'names' ]

    aNameTemplate[ 'href' ] = Encode( aURL.path )
    aNameTemplate[ 'name' ] = Encode( aContent.title )

    aTemplate[ 'names' ] = aNameTemplate

And here is the end result:

Et voilà.