Conditional categories
Asked Answered
S

3

6

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?

Serval answered 23/10, 2018 at 12:21 Comment(0)
I
4

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]]}} }}
Impasto answered 24/10, 2018 at 4:6 Comment(4)
They did appear under the unknown-category. I fixed that (includeonly-embracing). The categories are not hidden. I cleared the cache of the category-page and the template page, but no change: All pages still appear under the unknown-category.Serval
You mean when you open Unknown-category page, you find all pages using that template inside of it?Impasto
Exactly, they all appear there!Serval
Now they do not appear in the Unknown-category anymore but they still do not appear in the foo- or bar-category. :-(Serval
F
0

Do you run the jobqueue on your wiki? Linkstables are updated asynchronously and not at page save time.

https://www.mediawiki.org/wiki/Manual:Job_queue

https://www.mediawiki.org/wiki/Manual:RunJobs.php

Flammable answered 2/11, 2018 at 14:15 Comment(1)
Yes, this runs automatically every two hours and updates the categories that are not added conditionally. However the conditional-categories don't work.Serval
T
0

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.

Truism answered 5/2, 2019 at 0:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.