OpenWrt Forum Archive

Topic: uhttpd-mod-lua html templates, without luci

The content of this topic has been archived on 3 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hi,

I'd like to create a custom html web page via lua in OpenWRT. I don't want to push html string like below to do this task:

function handle_request(env)
        uhttpd.send("Status: 200 OK\r\n")
        uhttpd.send("Content-Type: text/html\r\n\r\n")
        uhttpd.send("<html>HTML GOES HERE</html>")
end

I want to do it like php and mod-php in apache:

<html>
<head></head>
<body>
<?php
$SOME_PHP_HERE;
?>
</body>
</html>

I've found https://keplerproject.github.io/cgilua/manual.html page, about cgilua. Lua Pages part of the page to be exact: https://keplerproject.github.io/cgilua/ … #templates, but without a reference to uhttpd.

Please note that, I've uninstalled luci, and all dependencies, except uhttpd, uhttpd-mod-ubus. I've installed uhttpd-mod-lua for this, but not sure if it's gonna help.

How can I accomplish this task?

Thank you.

I'm sorry, there is a misunderstanding in my question I guess.

I don't want to use php, I want to use lua. I gave php just for the sake of an example.

I want something like this, as in keplerproject link above:

<html>
<?lua
if cgilua.QUERY.language == 'english' then
  greeting = 'Hello World!'
elseif cgilua.QUERY.language == 'portuguese' then
  greeting = 'Olá Mundo!'
else
  greeting = '[unknown language]'
end
?>
<head>
  <title><%= greeting %></title>
</head>
<body>
  <strong><%= greeting %></strong>
</body>
</html>

https://keplerproject.github.io/cgilua/ … #templates

Any ideas on this fellas?

The discussion might have continued from here.