Module:Hatnote/doc: Difference between revisions

Content deleted Content added
add format link function
and findNamespaceId
Line 80:
: {{code|mHatnote._formatLink('Category:Lions')|lua}} &rarr; <nowiki>[[:Category:Lions]]</nowiki> &rarr; {{format hatnote link|Category:Lions}}
: {{code|mHatnote._formatLink('Lion#Etymology', 'Etymology of lion')|lua}} &rarr; <nowiki>[[Lion#Etymology|Etymology of lion]]</nowiki> &rarr; {{format hatnote link|Lion#Etymology|Etymology of lion}}
 
=== Find namespace id ===
 
<source lang="lua">
mHatnote._findNamespaceId(link, removeColon)
</source>
 
Finds the [[WP:NS|namespace id]] of the string <var>link</var>, which should be a valid page name, with or without the section name. This function will not work if the page name is enclosed with square brackets. When trying to parse the namespace name, colons are removed from the start of the link by default. This is helpful if users have specified colons when they are not strictly necessary. If you do not need to check for initial colons, set <var>removeColon</var> to false.
 
;Examples:
: {{code|mHatnote._findNamespaceId('Lion')|lua}} &rarr; 0
: {{code|mHatnote._findNamespaceId('Category:Lions')|lua}} &rarr; 14
: {{code|mHatnote._findNamespaceId(':Category:Lions')|lua}} &rarr; 14
: {{code|mHatnote._findNamespaceId(':Category:Lions', false)|lua}} &rarr; 0 (the namespace is detected as ":Category", rather than "Category")
 
<includeonly>{{#ifeq:{{SUBPAGENAME}}|sandbox||