User:Fimbulvetr/Reference
From A3! Wiki
< User:Fimbulvetr
Revision as of 07:42, 26 January 2018 by Fimbulvetr (talk | contribs) (Created page with "== #titleparts == This function separates a page title into segments based on slashes, then returns some of those segments as output. :<code><nowiki>{{#titleparts: pagename |...")
#titleparts
This function separates a page title into segments based on slashes, then returns some of those segments as output.
{{#titleparts: pagename | number of segments to return | first segment to return }}
If the number of segments to return parameter is not specified, it defaults to "0", which returns all the segments from the first segment to return (included). If the first segment to return parameter is not specified or is "0", it defaults to "1":
{{#titleparts: Talk:Foo/bar/baz/quok }}
→ Talk:Foo/bar/baz/quok
{{#titleparts: ''Talk:Foo''/bar/baz/quok | 1 }}
→ Talk:Foo See also {{ROOTPAGENAME}}.
{{#titleparts: ''Talk:Foo/bar''/baz/quok | 2 }}
→ Talk:Foo/bar
{{#titleparts: Talk:Foo/''bar/baz''/quok | 2 | 2 }}
→ bar/baz
{{#titleparts: Talk:Foo/''bar/baz/quok'' | | 2 }}
→ bar/baz/quok
{{#titleparts: Talk:Foo/bar/baz/quok | | 5 }}
→
Negative values are accepted for both values. Negative values for the number of segments to return parameter effectively 'strips' segments from the end of the string. Negative values for the first segment to return translates to "start with this segment counting from the right":
{{#titleparts: ''Talk:Foo/bar/baz''/quok | -1 }}
→ Talk:Foo/bar/baz Strips one segment from the end of the string. See also {{BASEPAGENAME}}.
{{#titleparts: Talk:Foo/bar/baz/quok | -4 }}
→ Strips all 4 segments from the end of the string
{{#titleparts: Talk:Foo/bar/baz/quok | -5 }}
→ Strips 5 segments from the end of the string (more than exist)
{{#titleparts: Talk:Foo/bar/baz/''quok'' | | -1 }}
→ quok Returns last segment. See also {{SUBPAGENAME}}.
{{#titleparts: Talk:Foo/''bar/baz''/quok | -1 | 2 }}
→ bar/baz Strips one segment from the end of the string, then returns the second segment and beyond
{{#titleparts: Talk:Foo/bar/''baz''/quok | -1 | -2 }}
→ baz Start copying at the second last element; strip one segment from the end of the string