lua-users home
lua-l archive

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

On Fri, Oct 15, 2010 at 3:33 PM, Jonathan Castello <> wrote:
> On Fri, Oct 15, 2010 at 1:31 PM, Alex Queiroz <> wrote:
>>     I thought that was a compliment. :)
> It certainly wasn't an insult. ;)

but the syntax is certainly ugly.  this is what i actually use:

function string:template(variables)
	return (self:gsub('{%%(.-)%%}', function (key) return
tostring(variables[key] or _G[key] or '') end))


global_footer = 'copyright for myself, inc.'

print (([[
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<html xmlns="";>
		<div id='header'><p>{%header%}</p></div>
		<div id='main'>
			<img src="{%picture_url%}" alt="{%picture_caption%}"/>
			<a src="{%exit_url%}">{%exit_text%}</a>
		<div id='footer'><p>{%global_footer%}</p></div>
</html>]]):template {
	title='page title',
	header= header div'',
	maintext = 'main part',
	picture_url = 'lolcats/purrr.jpg',
	picture_caption = 'lol',
	exit_url = 'somewhere/else.html',
	exit_text = 'lets go',