bungle / lua-resty-template

Templating Engine (HTML) for Lua and OpenResty.
BSD 3-Clause "New" or "Revised" License
909 stars 204 forks source link

is there a function some func like php's echo in {% %}? #27

Closed cuiweixie closed 4 years ago

cuiweixie commented 7 years ago

like this: {message} {% print("ssss") %} output: sssshello world expecting: hello wordssss the sss show not be at the begin?

cuiweixie commented 7 years ago

<a href ="{%

local function echo(s)
    ___[#___+1] =s
end
echo("http://www.baidu.com")

%}">baidu

I look into the code. and find this solution, is it ok?

bungle commented 7 years ago

Why not:

{{message)}
{{"ssss"}}
cuiweixie commented 7 years ago

sometimes the "ssss" maybe generated by some lua code.

bungle commented 7 years ago

Then just put that code in there?

{{ run_my_code("yeah!") }}
bungle commented 7 years ago

Another example:

{{ (function() return "sss" end)() }}
cuiweixie commented 7 years ago

I think a phper will feel more comfortable if we has a echo function. I am trying to move some php codes to openresty.

cuiweixie commented 7 years ago

a echo func could make you template more readable

bungle commented 7 years ago

Well, I can think about it, but if you are putting code (like a lot of it) in template, you are possibly doing it wrong (aka spaghetti).

cuiweixie commented 7 years ago

i will add it in resty.template.

bungle commented 7 years ago

Yes, PRs welcome. Not sure though if I will include it, but you can send it. Or just fork it.

cuiweixie commented 7 years ago

OK

cuiweixie commented 7 years ago

https://github.com/bungle/lua-resty-template/pull/28 here comes the PR.

bungle commented 7 years ago

@cuiweixie, thanks for the PR. Let's see if others vote this as well.