Topic on Extension talk:Arrays

Lady Aleena (talkcontribs)

I would like to make the following tiny, but I am not sure what will and will not break the functions.


 {{#arraydefine:array-list | {{{array}}}}}
 {{#ifeq: {{#arraysize:array-list}} | 1 |
   {{{array}}} [[Category:{{{array}}} category]] |
   {{#arrayprint:array-list||@@@@|<nowiki/>
   * @@@@ [[Category:@@@@ category]]}}
   }}

I am getting an array, then checking to see how many items there are. If there is one item, just print the array as a normal parameter with a category. If there are two or more, print the array as a list with each item getting its own category.

Right now it just looks bad. So, can someone please clean it up, and maybe offer better ways to write it?

Thank you in advance! Lady Aleena (talk) 06:16, 19 November 2017 (UTC)

Henryfunk (talkcontribs)

This answer perhaps goes in another direction than what you expected, but anyway: One change I would consider an improvement would be to change category names so they don't end in the string " category". It's redundant, and getting rid of it would in this case make your code 18 characters shorter :-)

Lady Aleena (talkcontribs)

The above use was as an example. I will put up the actual use if wanted. Lady Aleena (talk) 21:05, 23 November 2017 (UTC)

Henryfunk (talkcontribs)

Ah, OK. I don't think the code in your example can be tidied up much. Do post it here, if you find a better solution.

Dinoguy1000 (talkcontribs)

Do you mean to categorize the page(s) this code will be used on? If not, make sure to link the categories by adding <code>:</code> at the beginning of the link.

I think that's about how I'd do this too (except using StringFunctions, see below). Really the only option for shortening the code that I can see would be to just always output the items as list items, even when there's only one. Of course, if someone else knows a way to shorten this, I'd also be interested in seeing. =)

If StringFunctions are enabled on your wiki, I would recommend the following code instead:

{{#if: {{#pos:{{{array}}} | , }} |
{{#arraydefine:array-list | {{{array}}} }}{{#arrayprint:array-list||@@@@|<nowiki/>
* @@@@ [[Category:@@@@ category]]}} |
{{{array}}} [[Category:{{{array}}} category]]
}}

This lets you avoid touching array functions at all unless you have more than one item to display.

Lady Aleena (talkcontribs)

I was just looking for a way to "tidy" the code, make it look good. Sort of like HTML Tidy. Thank you for stopping by! Lady Aleena (talk) 20:20, 19 November 2017 (UTC)

I just realized that I might need to change the delimiter. Names can have commas in them, so I am going to try to use a semicolon. Lady Aleena (talk) 20:37, 19 November 2017 (UTC)

Reply to "Tidy array?"