- local viewns = setmetatable({}, {__index=_G})
- tpl.context.viewns = viewns
- viewns.write = luci.http.write
- viewns.include = function(name) tpl.Template(name):render(getfenv(2)) end
- viewns.translate = function(...) return require("luci.i18n").translate(...) end
- viewns.striptags = util.striptags
- viewns.controller = luci.http.getenv("SCRIPT_NAME")
- viewns.media = media
- viewns.theme = fs.basename(media)
- viewns.resource = luci.config.main.resourcebase
- viewns.REQUEST_URI = (luci.http.getenv("SCRIPT_NAME") or "") .. (luci.http.getenv("PATH_INFO") or "")
+ tpl.context.viewns = setmetatable({
+ write = luci.http.write;
+ include = function(name) tpl.Template(name):render(getfenv(2)) end;
+ translate = function(...) return require("luci.i18n").translate(...) end;
+ striptags = util.striptags;
+ media = media;
+ theme = fs.basename(media);
+ resource = luci.config.main.resourcebase
+ }, {__index=function(table, key)
+ if key == "controller" then
+ return build_url()
+ elseif key == "REQUEST_URI" then
+ return build_url(unpack(ctx.requestpath))
+ else
+ return rawget(table, key) or _G[key]
+ end
+ end})