luci-base, luci-lua-runtime: adjust Lua template environment
To maintain full compatibility with the old Lua runtime, templates rendered from a menu `template()` action must implicitly inherit the `luci.dispatcher` namespace as scope while other indirectly included templates must not. Fixes: #6105 Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
parent
08ae8d40a9
commit
fa17c1573f
3 changed files with 10 additions and 2 deletions
|
@ -774,7 +774,9 @@ function render_action(fn) {
|
||||||
function run_action(request_path, lang, tree, resolved, action) {
|
function run_action(request_path, lang, tree, resolved, action) {
|
||||||
switch (action?.type) {
|
switch (action?.type) {
|
||||||
case 'template':
|
case 'template':
|
||||||
runtime.render(action.path, {});
|
render_action(() => {
|
||||||
|
runtime.call('luci.dispatcher', 'render_lua_template', action.path);
|
||||||
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'view':
|
case 'view':
|
||||||
|
|
|
@ -354,6 +354,12 @@ function invoke_form_action(model, ...)
|
||||||
_G.L.include("footer")
|
_G.L.include("footer")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function render_lua_template(path)
|
||||||
|
local tpl = require "luci.template"
|
||||||
|
|
||||||
|
tpl.render(path, getfenv(1))
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
function call(name, ...)
|
function call(name, ...)
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -121,7 +121,7 @@ context.viewns = setmetatable({
|
||||||
elseif key == "resource" then
|
elseif key == "resource" then
|
||||||
return L.config.main.resourcebase
|
return L.config.main.resourcebase
|
||||||
else
|
else
|
||||||
return rawget(tbl, key) or disp[key] or _G[key] or L[key]
|
return rawget(tbl, key) or _G[key] or L[key]
|
||||||
end
|
end
|
||||||
end})
|
end})
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue