Conditional categories

Viewed 182

I'm using a template {{MyTemplate|foo}} which consists of the following code:

{{#switch: {{{1}}}
 | foo = [[Category:Foo]]
 | bar = [[Category:Bar]]
 | #default = [[Category:Unknown]]
}}

When I'm using it on a page, the categories show up nicely as wished at the bottom of that page. But unfortunately inside of that category-page (Category:Foo for example) the page doesn't show up.

If I add [[Category:Foo]] manually to that page, the page shows up in the Foo-category-page.

Any suggestions why this doesn't work via the template?

3 Answers

Does the template page that contain the previous code appear under Unknown category?. If yes, then any page contain that template must appear in it's category. You may just have to clear cache, and wait few seconds if you have a large wiki.

Make sure that foo & bar categories are not hidden in your wiki. See this: https://www.mediawiki.org/wiki/Help:Categories#Hidden_categories

EDIT

Also, try one of these solutions, which can do the same goal:

{{#switch: {{{1}}}
 | foo = [[Category:Foo]]
 | bar = [[Category:Bar]]
 | #default = [[Category:Unknown]]
}}

OR

{{#ifeq: {{{1}}} | foo | [[Category:Foo]] | {{#ifeq: {{{1}}} | bar | [[Category:Bar]] |  [[Category:Unknown]]}} }}

Cant understand the description to your problem, but anyway, it seems like you could achieve the same goal by:

{{#vardefine: my_category |wow}}
[[Category: {{#ifeq: {{#var:my_category}}| default| unknown| {{#var:my_category}} }} ]]

Which adds this category to the page, In my opinion, you should use switch when you are adding category in any case but also decide not to add category in another case.

If you are adding category in all cases, you can write as i wrote above, or export the final category to another variable and use it inside the category.

As for your problem, you can use "?action=purge" for this page, if that wont work, write here some more info.

Related