Topic on Project:Support desk

Help with template argument, please!

5
Kri (talkcontribs)

Hi! The template {{Recipe}} on Wikibooks has an optional argument, taking a sort key which is used when the article the template is used in is sorted in the category Recipes (I will get there in a moment). {{Recipe}} also calls the template {{Cookbook article type}}, to which it passes on the optional parameter (if it is provided with it), but now labels it "sortby", since that is the label {{Cookbook article type}} expects it to have. {{Cookbook article type}} then adds the article to the category Recipes (instead of letting {{Recipe}} do that) and uses the argument labeled "sortby" as the sort key (if it is provided with it). However, somewhere this sort key is lost, and articles that use the template {{Recipe}} and provide it with a sort key, are not sorted by their sort key but by the article names, such as Döner kebab which provides the template with the sort key "Doner kebab" but nevertheless ends up last in the list of recipes starting at "D" in the category. Can someone please help me to understand why the code isn't working as expected?

Bawolff (talkcontribs)

It looks like this is no longer happening, so I can't really comment on why it did happen. Most likely the sortkey was getting overriden later or something of that nature. I tried to answer some of your other questions about sorting on b:template:Recipe.

Kri (talkcontribs)

Döner kebab still ends up last under "D" in the category Recipes for me. Does system or web browser affect this behavior?

Bawolff (talkcontribs)

Whoops, I only looked at the beef recipes category. Your correct its still sorted at end. b:Special:ExpandTemplates seems to indicate that [[Category:Recipes|Döner kebab]] appears on the page, so that would by why.


Looking at the various templates, it appears that dynamically specifying both the parameter name and value in one go doesn't work (I can't remember if there's a way to do so, I thought there was, but I can't remember). Anyhow, an easy workarround is to either set the sortkey with {{DEFAULTSORT}} and not worry about setting sortkeys on individual categories, or change template:Recipe to be something like:

{{Cookbook page type|Recipe|Recipes|navigation=[[:Category:Cookbook|Cookbook]] {{!}} [[:Category:Ingredients|Ingredients]]|noincludecat={{{noincludecat|}}}|sortkey={{{1|{{PAGENAME}}}}} }}
Kri (talkcontribs)

Thanks. It seems like an equals sign in an {{#if:}} clause caused some problem.

Reply to "Help with template argument, please!"