Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditional categories

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?

like image 332
user2033412 Avatar asked Oct 23 '18 12:10

user2033412


1 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]]}} }}
like image 139
ASammour Avatar answered Oct 24 '22 04:10

ASammour