Module:title/getCurrentTitle

From Linguifex
Revision as of 09:12, 28 June 2025 by Sware (talk | contribs) (Created page with "local get_current_title = mw.title.getCurrentTitle --[==[ A modified version of {mw.title.getCurrentTitle}, which returns the title object for the current title. If the additional optional parameter {fragment} is given, the returned title object will have that value as the fragment, which is the part of the title that comes after {#}, referring to a specific section on the page (e.g. in {"foo#bar"}, the fragment is {"bar"}). This is a convenience function, which is gen...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Documentation for this module may be created at Module:title/getCurrentTitle/doc

local get_current_title = mw.title.getCurrentTitle

--[==[
A modified version of {mw.title.getCurrentTitle}, which returns the title object for the current title. If the additional optional parameter {fragment} is given, the returned title object will have that value as the fragment, which is the part of the title that comes after {#}, referring to a specific section on the page (e.g. in {"foo#bar"}, the fragment is {"bar"}).

This is a convenience function, which is generally only useful when dealing with fragment-only links, as these resolve to other sections on the current page (e.g. [[#foo]] is a link to the section "foo" on the current page). If the {fragment} parameter is not needed, it is more efficient to simply call {mw.title.getCurrentTitle} directly.]==]
return function(fragment)
	if fragment == nil then
		return get_current_title()
	end
	local current_title = get_current_title()
	current_title.fragment = fragment
	return current_title
end