Шаблон:When on basepage
Ця сторінка містить неперекладені фрагменти іноземною мовою. |
This is the {{When on basepage}} meta-template. It helps other templates detect if they are on a basepage (i.e. a page whose name matches the pattern "x:x") subpage ("x:x/x") or subsubpage ("x:x/x/x").
An alternative way to detect whether a page is a subpage is to combine the parser functions #ifeq:
and #titleparts
. See Alternatives for simpler text below.
Використання
ред.{{When on basepage |result if on a basepage (|result if on a subpage) (|result if on a subsubpage) (|page=pagename)}}
For example, {{When on basepage|Basepage|Subpage}} on the page "User:Example" would return: Basepage
whilst on "User:Example/page" (or "User:Example/page/page", "User:Example/page/page/page", etc.) it would return: Subpage
On a subsubpage such as "User:Example/page/page" (or "User:Example/page/page/page", etc.), {{When on basepage|Basepage|Subpage|Subsubpage}} would return: Subsubpage
Use an empty parameter to specify no action for a particular type of page. {{When on basepage|Basepage||Subsubpage}} on "User:Example/page", for example, would return nothing, but would return "Subsubpage" if on "User:Example/page/page", "User:Example/page/page/page", etc. (and "Basepage" if on "User:Example").
Handling equals-signs ("=")
ред.Use numbered parameters if their values include equals-signs ("="), i.e.
- {{When on basepage |1=basepage result (|2=subpage result) (|3=subsubpage result)}}
page parameter
ред.The page parameter is included for testing/demonstration. For example:
- {{When on basepage |(basepage result)|(subpage result)|page=User:Example/test}}
Regardless of where the above is placed, it will return: (subpage result)
(because "User:Example/test" is a subpage). The page doesn't have to exist.
If page is left empty (|page=
) or undefined, the page where the template is transcluded (i.e. {{PAGENAME}}
) is used.
page also accepts variables, e.g. {{When on basepage|(basepage result)|(subpage result)|page={{{page|}}} }}
Технічне зауваження
ред.This template detects subpages in all namespaces, including those without the MediaWiki subpage feature enabled.
Alternatives for simpler text
ред.A subpage can be detected without using another template, by instead using the title-splitting parser function #titleparts
with #ifeq
:
{{#ifeq:{{#titleparts:{{PAGENAME}}|1|1}}|{{PAGENAME}} | [...code if on a basepage...] | [...code if on a subpage...] }}
For example, many templates can check if the page is a /sandbox version, by the similar markup with #ifeq
and #titleparts
:
- {{#ifeq: {{#titleparts:{{PAGENAME}}|1|1}} | {{PAGENAME}}
- | {{documentation}}
- | {{template sandbox notice}}
- }}
That simple logic works because Template:Template sandbox notice also checks the page name for "/sandbox" before displaying the sandbox notice; otherwise, any other subpage would show no extra text. By avoiding a template, and using a single #ifeq
, then the processing uses only +2 expansion depth levels, rather than +7 levels, and avoids "wp:exceeded template limits" inside a complex /doc page.
Див. також
ред.Прості у використанні шаблони визначення простору:
- {{main other}} — статей.
- {{template other}} — шаблонів.
- {{category other}} — категорій.
- {{file other}} — файлів (зображень).
- {{talk other}} — сторінок обговорень.
- {{user other}} — сторінок користувачів.
- {{wikipedia other}} — сторінок «Вікіпедія:».
- {{help other}} — довідки.
- {{portal other}} — порталів.
Складніші шаблони визначення простору:
- {{namespace detect}} — Дуже універсальний.
- {{namespace detect showall}} — Надзвичайно універсальний, має повторне використання вхідних даних.
- {{talkspace detect}} — Для визначення сторінок обговорень у різних просторах.
- {{main talk other}} — Відокремлює деякі простори.
Для визначення та обробки назв сторінок:
- {{pgn}} — Може розбирати на частини і збирати докупи назви сторінок у різні способи.
- {{when on basepage}} — Для визначення чи на основній сторінці, чи на підсторінці, чи на підпідсторінці.
- {{when pagename is}} — Для співставлення із взірцем назви сторінки.
- {{if pagename multi}} — Для співставлення із взірцем назви сторінки, має повторне використання вхідних даних.
- {{IP-user other}} — Для визначення сторінок анонімних користувачів.
Технічна інформація:
- Вікіпедія:Простір назв — Список просторів назв.
- mw:Help:Magic words — Про
{{NAMESPACE}}
тощо. - mw:Help:Extension:ParserFunctions — Про
{{#ifeq:|||}}
тощо.
|
Документація вище включена з Шаблон:When on basepage/документація. (ред. | історія) Дописувачі можуть експериментувати на підсторінках пісочниця (створити | дзеркало) та тести (створити) цього шаблону. Будь ласка, додавайте категорії до підсторінки /документація. Підсторінки цього шаблону. |