Template:ReturnToParent: Difference between revisions
Spacetrain31 (talk | contribs) No edit summary |
Spacetrain31 (talk | contribs) No edit summary |
||
| Line 21: | Line 21: | ||
* <code><nowiki>{{Return to parent|Help}}</nowiki></code> | * <code><nowiki>{{Return to parent|Help}}</nowiki></code> | ||
* <code><nowiki>{{Return to parent|parent=Portal:Contents|text=← Back to Contents}}</nowiki></code> | * <code><nowiki>{{Return to parent|parent=Portal:Contents|text=← Back to Contents}}</nowiki></code> | ||
== Lua Module == | |||
This template requires '''Module:ParentPage'''. Create it with the following code: | |||
<syntaxhighlight lang="lua"> | |||
local p = {} | |||
function p.getParent(frame) | |||
local pagename = frame.args[1] or mw.title.getCurrentTitle().fullText | |||
local parent = pagename:match("^(.+)/[^/]+$") | |||
if parent then | |||
return parent | |||
else | |||
return "" | |||
end | |||
end | |||
function p.getParentName(frame) | |||
local pagename = frame.args[1] or mw.title.getCurrentTitle().fullText | |||
local parent = pagename:match("^(.+)/[^/]+$") | |||
if parent then | |||
-- Remove namespace prefix for display | |||
local displayName = parent:match("^[^:]+:(.+)$") or parent | |||
return displayName | |||
else | |||
return "" | |||
end | |||
end | |||
return p | |||
</syntaxhighlight> | |||
[[Category:Navigation templates]] | [[Category:Navigation templates]] | ||
| Line 30: | Line 63: | ||
|{{#if:{{{1|}}} | |{{#if:{{{1|}}} | ||
|[[{{{1}}}|← Return to {{{1}}}]] | |[[{{{1}}}|← Return to {{{1}}}]] | ||
|{{# | |{{#if:{{#invoke:ParentPage|getParent}} | ||
|[[{{ | |[[{{#invoke:ParentPage|getParent}}|← Return to {{#invoke:ParentPage|getParentName}}]] | ||
| | |||
|<span class="error">This is not a subpage</span> | |<span class="error">This is not a subpage</span> | ||
}} | }} | ||
}} | }} | ||
}}</includeonly> | }}</includeonly> | ||