Search code examples
mediawikimediawiki-extensionssemantic-mediawiki

Is there a way to automatically create categories from a list of items?


I want to add some recipes to a part of my Mediawiki site and have each ingredient create a relevant category.

This is easy to do by hand, but subject to human error - each ingredient has to be entered twice.

for example


* [[category:apples]] apples
* [[category:bananas]] bananas
* [[category:cherries]] cherries

This works, but I feel there should be a way to automate it however I'm not really sure of what the best way forward would be. Is there already an extension to do this (I've searched on all the terms I can think of), should I be writing a script ? Is there some other method to solve this that I should be looking at ?


Solution

  • You could use a template, lets call it Template:Ingredient,

    <includeonly>* [[Category:{{{1}}}]] {{{1}}}</includeonly>
    

    Then call it in your page with:

    {{Ingredient|apples}}
    

    This will both display the ingredient name and add the page to the category.