Jump to content

Template talk:Template parameter value

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Aidan9382 (talk | contribs) at 07:39, 15 February 2024 (Can it just detect if the template is there: Reply). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Is using this going to cause problems?

This template is now used in a template {{Annotated link}} with the potential of being used several hundred times in some articles (that is several hundred times in the same article) and in hundreds or possibly thousands of articles. I have just seen the deletion discussion, and it does not fill me with confidence. Will this do what I want it to, or is something going to break spectacularly? Please ping with reply. Cheers, · · · Peter (Southwood) (talk): 11:15, 15 September 2018 (UTC)[reply]

@Pbsouthwood: Taking a look at the documentation, I see no reason why this would break. It'll do what you want. It's already in used in hundreds of articles in {{Aired episodes}} with no issues. -- AlexTW 11:26, 15 September 2018 (UTC)[reply]
Thanks, I will take your word for that as I do not have the detail knowledge to work it out for myself. Cheers, · · · Peter (Southwood) (talk): 12:00, 15 September 2018 (UTC)[reply]

There is currently a bug with piped links, see example below:

  • {{Template parameter value|Charmander|Infobox video game character|1|firstgame|1}} ->

The result should have been [[Pokémon Red and Blue|''Pokémon Red'' and ''Blue'']]. --Gonnym (talk) 19:48, 1 February 2019 (UTC)[reply]

I am aware, and I've been looking into fixing this. Cheers. -- /Alex/21 22:49, 1 February 2019 (UTC)[reply]

Not handling nesting correctly

If a parameter value includes a single nested transclusion (multiple ones are not handled), the last match() does not work correctly. In my fork, I have changed

content = string.match(content, '^([^|}]*{{[^}]+}}[^|}]*)|') or string.match(content, '([^|}]+)')

to

content = string.match(content, '^([^|{}]*{{[^}]+}}[^|}]*)[|}]') or string.match(content, '([^|}]+)')

The next line then preprocess()es the transclussion correctly, as was its intention. This was likely not found before, because short-descriptions shouldn't have such, but my fork does.

Dpleibovitz (talk) 23:34, 12 May 2019 (UTC)[reply]

Problem when unnamed parameter is labeled with number

In some cases, it is necessary to label an unnamed parameter with a number, like |1=. A common case is when the parameter's value contains an equals sign (=).

When this template attempts to extract the value of the first unnamed parameter, it does so incorrectly. This invocation:

{{Template parameter value|Outline of bicycles|Short description|1|1|1}}

should yield:

Overview of and topical guide to bicycles

But it instead yields:

1=Overview of and topical guide to bicycles

This is causing trouble with {{Annotated link}}. See Template talk:Annotated link for details.

Can someone please attempt to fix this bug? – Jonesey95 (talk) 16:37, 19 January 2020 (UTC)[reply]

Well crap, I just spent an hour debugging what turns out to be exactly this same situation (the 1= trick to pass a parameter containing an equals-sign breaking weirdly in the short-description/annotated-link handlers). DMacks (talk) 17:54, 10 March 2021 (UTC)[reply]
And it's actually worse than just an explicitly-numbered positional parameter. In:
{{foo|x=y}}
the positional {{{1}}} parameter is null, but {{template parameter value}} returns "x=y". That's in the first slot after the template-name, but it's named to other than parameter "1". DMacks (talk) 18:01, 10 March 2021 (UTC)[reply]

Redirects

This template works great for me--truly a Godsend!--except if pages get moved/renamed, as it doesn't recognise redirects. I took a stab at adding that functionality in the module's sandbox, but so far have failed (it shouldn't be too hard; just my Lua is now rusty). Can a blessed soul please shed some light? Cheers. — Guarapiranga  12:13, 8 May 2022 (UTC)[reply]

Broken instance

Trying to use {{Template parameter value|Template:Adminstats/GorillaWarfare|Adminstats/core|1|ed}} at Molly White (writer), I'm getting no result:


Any idea what I'm doing wrong or what's broken? {{u|Sdkb}}talk 17:36, 30 May 2022 (UTC)[reply]

No clue why TPV isn't working, but it isn't necessary here -> {{Adminstats/GorillaWarfare|style=raw ed+del}} -> 25424. That is, if it's appropriate to include a live-updating edit count at all, which I'm not convinced of (do any sources make that connection?). * Pppery * it has begun... 17:52, 30 May 2022 (UTC)[reply]
... and the template in question hasn't been updated since 2013 for some reason. * Pppery * it has begun... 17:55, 30 May 2022 (UTC)[reply]
Thanks, @Pppery! That's a much simpler solution lol. And yes, I noticed the lack of updating; I assume that's because the template wasn't used anywhere, so I'll put it in my sandbox for a day or two and see if it updates. On necessity, I'm going to have it round to a more approximate count, the same as it currently does. {{u|Sdkb}}talk 18:44, 30 May 2022 (UTC)[reply]

There is now a case insensitive version of this template...

... in the sandbox. And

are test cases. Guarapiranga  23:13, 15 June 2022 (UTC)[reply]

Expensive call

An issue was brought up at Template talk:Annotated link#Is this template very expensive, or am I doing it wrong? {{Annotated link|Table of bases}} makes two calls (I think) of {{Template parameter value|Table of bases|Short description|1|1|1}}. A single call has "Lua time usage 5.500/10.000 seconds". Two calls fails with "The time allocated for running scripts has expired". Table of bases has a table with around 9000 cells. PrimeHunter (talk) 13:04, 19 November 2022 (UTC)[reply]

in case it is relevant, table of bases has a WP:short description of "none", for which the template has special handling. --𝕁𝕄𝔽 (talk) 18:51, 19 November 2022 (UTC)[reply]
That was yesterday.[1] It currently says {{Short description|0 to 74 in base 2 to 36}}. PrimeHunter (talk) 23:46, 19 November 2022 (UTC)[reply]

Improved version

Aidan9382 has been working on an improved version in Module:Template parameter value/sandbox with a new ignoreSubtemplates option, and some other improvements. Aidan, please give the details :) — Martin (MSGJ · talk) 13:08, 21 February 2023 (UTC)[reply]

Sure. I've been working on a major change to the module to try and make it more robust compared to the current implementation, which can quickly fall apart given a complex situation for a number of reasons. There are a lot of changes, so I've tried to summarise the key points below.
  • Bug fixes
    • Template grabbing is now correctly restricted. Instead of grabbing all wikitext to exist beyond the start of the template, it will now stop at the end of the template to avoid processing further. This is mainly to prevent extreme GIGO.
    • Numerical indexes can now be grabbed regardless of if they are referred to as |1=XYZ or |XYZ. Numerical index grabbing should also be far more reliable in general for the reason provided below.
    • The entire fetching of parameters has been changed, using Module:Transcluder's getParameters function instead of regexs, which ensures parameters are grabbed faithfully, avoiding unreasonble cutoffs (having the value {{{1|XYZ}}} becoming {{{1 or having grabbing W from {{XYZ|W={{ABC|1|2|3}}}} return {{ABC), making subtemplate grabbing possible.
  • New features
    • ignore_subtemplates or ist (better name suggestions welcome) - enabling this will avoid capturing the parameters of any subtemplates. This allows for much safer targetting (E.g. instead of looking for the 3rd occurance of _P in the first occurance of PT in {{PT|1={{T1|_P=A}}, {{T2|_P=B}}|_P=C}}, which could easily be broken by a number of changes (moving of the _P, adding another subtemplate involving _P, etc), you can simply look for _P in PT while ignoring subtemplates), which rules out most chances for GIGO or later maintenance.
    • A module entry point (p.getValue) to allow this to be used by both modules and templates (how the options table works will be properly documented in /doc if implemented).
  • Notes
    • In terms of backwards compatability and replicated existing behaviour, I've tried as hard as I can tokeep the behaviour of the current module the same as it was. For this reason, the ignore subtemplates option is off by default, as this is how the existing implementation functions in practice. Most existing implementations should, therefore, not require maintenance. However, there are some intentional breaking changes.
      • One is that templates will no longer match if just the start of the name is the same, instead requiring the entire name of the template to match. This means that examples like one on the doc page ({{Template parameter value|Vikings (season 4)|Episode list|2|LineColor}}, since changed) would not work, as the template it actually wants is Episode list/sublist, and the template parameter would need to be modified to accomodate this.
      • Another is that numbered parameters are handled differently. This means the behaviour seen in the above section, #Problem when unnamed parameter is labeled with number, would no longer occur, as instead of looking for the 3rd pipe, it will instead look for the parameter 3. This doesn't present concerns if the entire template uses numerical parameters, but if it was to use both numbered and not numbered, this could quickly cause problems with not grabbing what it initially did, but there's no way to fix this in the code without making the functionality objectively worse, so these should also be manually fixed.
    • Note, however, that I've looked through most of the 59 active uses (the rest are indirect transclusions) of the template as of now, and can't find a case where these changes cause problems (except for this which I've fixed), so this should be fine. Infact, this would fix some issues on current pages (See here and here). There may also be other breaking changes I haven't noticed given the lack of available testcases other than whats available on the /doc (tested here), but this should be unlikely.
    • Couple of questions for those technically knowledgable about this module: is there any specific reason for this line which removes newlines or this line which preprocess the text? I'm confused what purpose the first one has and I can't think of a good reason to keep the second since it feels excessive (what if we want the raw? what do we do then?). I've left them implemented for now, but I'd be willing to remove them if there's no reason to keep them around.
These changes could also render {{Get parameter}} redundant, as the premise of that template was one that, while worse than this one in most situations, could supposedly handle more complex syntax than what this originally could. Considering this is no longer the case, chances are that template could probably be merged/replaced with this one if the change is implemented. I've left below a comparison using the example given on it's doc page to show it's up for the job.
{{Get parameter}} vs live and sandbox of {{Template parameter value}}
Thougts? Aidan9382 (talk) 18:10, 21 February 2023 (UTC)[reply]
@User:Alex 21 would you like to comment? — Martin (MSGJ · talk) 22:09, 21 February 2023 (UTC)[reply]
Oh absolutely, if there's a more improved version then I absolutely support it replacing this version. I always meant to get around to fixing it properly, as I do recognize how buggy this template is, given that I created it almost five years ago. -- Alex_21 TALK 22:35, 21 February 2023 (UTC)[reply]

@MSGJ and Alex 21: If there's no issues with the new version, I'll probably go ahead and implement it into live soon. But before that - Alex 21, whats the purpose of this line removing newlines from the content? was it some limitation of the previous regexs used or is there some other reason to not want newlines? Aidan9382 (talk) 20:59, 1 March 2023 (UTC)[reply]

If I recall properly, this version would only work if all the content was on the same "line", as it were, in case parameter values were spread across multiple new lines. (I think. It's been five years since I created this infernal mod.) If, however, the new version does not need this, then by all means I'm fine with its removal. -- Alex_21 TALK 06:52, 2 March 2023 (UTC)[reply]
I can't imagine a reason the new system needs to worry about newlines screwing anything up, so I've gone ahead and removed that. Thanks for the input. I'll probably release the update within a few hours, just doing a final check to make sure nothing falls apart (I've re-added preprocessing to the Template's entry point after realising text like {{{ABC|XYZ}}} doesn't get evaluated automatically into XYZ when coming out of a module, which I wasn't expecting). Aidan9382 (talk) 14:06, 2 March 2023 (UTC)[reply]
I've pushed the changes and updated the docs with some details and templatedata (feel free to expand upon it, as I'm quite bad at explaining things). Hopefully this new version helps out. Aidan9382 (talk) 21:56, 2 March 2023 (UTC)[reply]
Thanks for your work on this! — Martin (MSGJ · talk) 21:58, 2 March 2023 (UTC)[reply]

@Aidan9382: Could you look into why this is happening? The minimal reproducer seems to be {{template parameter value|The Great North|Infobox television|1|num_episodes|1}}, which worked in the old version but not the new version. * Pppery * it has begun... 00:07, 3 March 2023 (UTC)[reply]

@Pppery: The issue appears to be coming from the comment inside the infobox, <!--Please do NOT change to {{Plainlist| as this is [...]-->. The new version doesn't want to overgrab content, so it will try match from the start to the end of the template using {%b{}}, but the comment means the template never finishes matching cause the count is unbalanced. In this case, Infobox television will be the only template there that doesn't get picked up, and all other templates capture fine. I'll work on something to temporarily remove comments during processing, which should get around this issue. Surprised I hadn't caught this during testing though - sorry about that. Aidan9382 (talk) 04:50, 3 March 2023 (UTC)[reply]
Should be fixed for that page, as well as any other similar failed case involving comments. If you find any other processing errors I missed, do let me know. Thanks! Aidan9382 (talk) 05:10, 3 March 2023 (UTC)[reply]

Ignore blank values

Is there any way to find the first non-blank parameter? For example on the page

{{WPBS|
{{WikiProject Fungi|class=|importance=low}}
{{WikiProject Rabbits|class=stub|importance=low}}
}}

I would like

{{template parameter value|{{FULLPAGENAME}}|WPSB||class}}

to equal "stub" rather than blank. Any ideas? — Martin (MSGJ · talk) 21:17, 28 April 2023 (UTC)[reply]

There's no existing way to do this right now. I have 2 ideas in mind - either a parameter like ignoreblank in which the code would just pretend blank parameters don't exist, or an option to have it return all the parameters under the requested template and let whatever is using it figure out what it wants itself (though I'm not sure how this would work for the template entry point). Thoughts? Aidan9382 (talk) 22:40, 28 April 2023 (UTC)[reply]
I could see the utility in both options. For now, ignoreblank would probably do exactly what I need. But I could certainly see the use case for returning a table of all values in case further processing was needed. I think we had a similar conversation about ignoring blank values on another talk page, but can't quite remember what we decided ... — Martin (MSGJ · talk) 21:58, 29 April 2023 (UTC)[reply]
You might be thinking about User talk:Aidan9382#Question, though that was more about there not being a parameter period. I've implemented some test code that should create the effect you asked for. Using {{Outer| {{Inner1|class=}} {{Inner2|class=a}} {{Inner3|class=}} {{Inner4|class=b}} }} as an example input, the output currently goes as follows:
Examples
{{Template parameter value|PAGE|Outer||class}} -> Blank
{{Template parameter value|PAGE|Outer||class|2}} -> a
{{Template parameter value|PAGE|Outer||class|4}} -> b
{{Template parameter value|PAGE|Outer||class|ignore_blank=y}} -> a
{{Template parameter value|PAGE|Outer||class|ignore_blank=y|2}} -> b
{{Template parameter value|PAGE|Outer||class|ignore_blank=y|4}} -> No parameter found, since there's only 2 non-blank parameters
Does this sound right? Aidan9382 (talk) 07:22, 30 April 2023 (UTC)[reply]
Looks great. I assume this will work with positionals too? — Martin (MSGJ · talk) 17:09, 30 April 2023 (UTC)[reply]
Assuming you mean {{Template|X||Z}}, yes, since positionals are treated like every other parameter. Aidan9382 (talk) 19:42, 30 April 2023 (UTC)[reply]
Please let me know when this feature is available, thanks — Martin (MSGJ · talk) 11:37, 2 May 2023 (UTC)[reply]
I'll leave a reply here once it's up and active. Aidan9382 (talk) 15:36, 2 May 2023 (UTC)[reply]

Question: if |ignore_blank=true and only blank parameters are found, should success be returned true or false? — Martin (MSGJ · talk) 14:30, 2 May 2023 (UTC)[reply]

The success state will continue to return true regardless of if a non-blank parameter is found, as it only returns false when the template or page itself can't be found. That behaviour is based off of the conversation on this thread on my talk page, down near the end. Aidan9382 (talk) 15:36, 2 May 2023 (UTC)[reply]

Show only subtemplates

One more small request. Would a show_only_subtemplates parameter be possible, to complement ignore_subtemplates? — Martin (MSGJ · talk) 12:47, 2 May 2023 (UTC)[reply]

I can probably make this, yes, though I may not name the option that exactly. I'll see what I can work up in the sandbox. Aidan9382 (talk) 15:36, 2 May 2023 (UTC)[reply]
I've implemented this in the sandbox as only_subtemplates. If the functionality for this and ignore_blank seem fine, I'll go ahead and push these changes. Aidan9382 (talk) 18:59, 2 May 2023 (UTC)[reply]
Haven't tested extensively, but seems to work well for my use case. I'm sure there is a good reason to use different parameter names for the invokable vs direct call, i.e. only_subtemplates vs onlySubtemplates, but it keeps confusing me ... — Martin (MSGJ · talk) 21:11, 2 May 2023 (UTC)[reply]
There is no good reason, I just had ended up doing it that way when I was initially making it. Infact, I've now made it accept both forms for the module entry point to fix the inconsistency of the module entry point without breaking existing uses. Aidan9382 (talk) 05:47, 3 May 2023 (UTC)[reply]
Great - I've switched my uses to the underscore method if you want to settle on that form — Martin (MSGJ · talk) 11:36, 3 May 2023 (UTC)[reply]
Thanks for that. I'll likely work on migrating away from camelCase entirely over time and then eventually removing it from the code to match the template usage, but for now I'll support both through the module entry point. I've gone ahead and pushed the changes to live aswell, so both ignore_blank and only_subtemplates are now available. I'll update the documentation later when I've got time. Aidan9382 (talk) 12:09, 3 May 2023 (UTC)[reply]
Many thanks — Martin (MSGJ · talk) 13:39, 3 May 2023 (UTC)[reply]

Case sensitive

{{article assessment}} and {{Article assessment}} refers to the same template, but currently this module does not treat them the same. Please could you make the first letter case-insensitive? — Martin (MSGJ · talk) 12:02, 29 June 2023 (UTC)[reply]

@MSGJ  Done I believe this should work now. (Any other Lua programmer, correct me if I've done anything wrong.) -- Alex_21 TALK 12:55, 29 June 2023 (UTC)[reply]
Works a treat, thank you! Bit surprised I didn't discover this earlier — Martin (MSGJ · talk) 07:54, 30 June 2023 (UTC)[reply]

Bizarre and inexplicable bug

This just plain deadass does not work on Wikipedia:Wikipedia Signpost/Templates/Signpost-article-header-v2. I have extensively tried to debug this and not come up with anything at all. I'll post my research on this below. jp×g🗯️ 00:23, 23 December 2023 (UTC)[reply]

Essentially:

{{Template parameter value|Wikipedia:Wikipedia Signpost/Next issue/Arbitration report|Signpost draft|1|piccyfilename|1}} works fine.

Exact same formatting of same parameter with same value on a different page with a different template.

{{Template parameter value|Wikipedia:Wikipedia Signpost/2023-11-06/Arbitration report|Wikipedia:Wikipedia Signpost/Templates/Signpost-article-header-v2|1|piccyfilename|1}}: BUSTED!

Returns nothing. This is completely fixed if I change the name of the template in the article's code to {{Asdfasdfasdf}} and then change the template parameter value to be scraping params out of Asdfasdfasdf and run it on the exact same page. Same params, same page, same code. But different template name!

{{Template parameter value|Wikipedia:Wikipedia Signpost/2023-11-06/Arbitration report|Wikipedia:Wikipedia Signpost/Templates/RSS description|1|1|1}}

This works fine -- same page. Every template can be parsed out of the page except article-header-v2 for some reason.

  • Title issues, parsing other stuff wrong and getting the wrong pages, etc. No because it gets the RSS fine.
  • Module can't process linebreaks in template No because it does it fine for the draft template params.
  • Weird thing with the {{{1|title goes here}}} thing No because it also completely woofs on the piccy params which are totally normal. In fact they are LITERALLY THE EXACT SAME in the draft article and in the article article (whitespace etc) but work for the draft and not the article.
  • Module requires templates to start with Template: Then why does it work for Wikipedia:Wikipedia Signpost/Templates/RSS description?
  • Module woofs when there's wikitext in a template: This is possible, the RSS template has no wikitext and the article header template does. Hmmmm.
Yeah there's no wikitext at all in the draft template. If I add some will it break? Then I will know it's this.
NO: it works fine when I put link text in the draft template, and the article one doesn't work even when I remove all wikitext from the header template.

What is going on here? Does anybody have any idea why this specific header template would cause the module to fail completely? jp×g🗯️ 00:28, 23 December 2023 (UTC)[reply]

@JPxG: After a quick look, the issue appears to be how the wanted template text is handled (the template name is getting treated like a regex, and - is a lua regex term that is equivilant to *? in standard regex). The module probably shouldn't be automatically treating inputs as regex and instead escaping them beforehand unless specified otherwise, so I'll work on implementing that, just need to make sure it won't break any existing uses first. Aidan9382 (talk) 07:02, 23 December 2023 (UTC)[reply]
After getting distracted for long enough doing other things, I've done what I said above (your use case should now work fine), and left in treat_as_regex (better naming ideas welcome) to allow treating the template name as a regex match (which no existing use cases appear to do anyways). Aidan9382 (talk) 14:17, 23 December 2023 (UTC)[reply]
Wow, it's beautiful. Excellent! I wouldn't have dreamed of a fix the next day -- I figured I was just whining into the void. Thank you very much for this. jp×g🗯️ 14:21, 24 December 2023 (UTC)[reply]

Can it just detect if the template is there

Hi, I looked everywhere for a template or module that can simply detect whether a template exists on a page, and couldn't find one; basically I'd like something similar to Cirrus hastemplate except returns boolean. My use cases involve searching for templates on redirect pages; for example, I'd like to do something like this:

If you know of a template that does this, can you link it for me? Otherwise, tmpv already knows whether a template is on the page, so could we extend parameter usage a bit to do this?

  • {{tmpv|Transgender history in Australia|R with possibilities}} ⟶ 1 if the template exists on the page, else empty
  • {{tmpv|Transgender history in Australia|R with possibilities|8}} ⟶ 1 if the template exists 8 (or more) times on the page, else empty

If the top one is problematic due to param value defaulting, then maybe this to make it explicit:

  • {{tmpv|Transgender history in Australia|R with possibilities|0}} ⟶ 1 if the template exists on the page, else empty

I could probably brute-force this with a couple of functions in Module:String, but it seems a shame when something like this either exists as a template already, or might be a not too complex enhancement to tmpv. Thanks! Mathglot (talk) 22:20, 14 February 2024 (UTC)[reply]

Yes, the getValue function in Module:Template parameter value will return false if the template does not exist on the page — Martin (MSGJ · talk) 22:45, 14 February 2024 (UTC)[reply]
Perfect! Thank you. Maybe it's worth wrapping that, unless there's a reason not to. Mathglot (talk) 22:56, 14 February 2024 (UTC)[reply]
I'm getting a missing param error with:
{{#invoke:Template parameter value|getValue|Transgender history in Australia|R with possibilities}}
That gives me falseMissing required parameters 'templates' and 'parameter', which seems consistent with line 92. Or am I invoking it wrong? The module doc is rather thin, and it's hard to tell. Mathglot (talk) 23:07, 14 February 2024 (UTC)[reply]
getValue is designed to be a module entry point, while main is designed to be a template entry point (essentially a wrapper for getValue). Invoking getValue as a template will never work, since you can only ever pass the frame, and getValue expects 2 arguments at least. Also, main currently returns an empty string upon failing in any way, so testing for errors via that will not work either.
I could see adding a simplified version of the getValue function called hasTemplate or something similar as a new template method, which would purely test if the wanted template exist, or modifying getValue and main to support no parameter given to mean a template test (though the usage of such a thing may appear unintuitive, as something called "parameter value" wouldn't be doing anything with parameters), or just having main report its errors through the template method. Do any of these sound particularly useful? Aidan9382 (talk) 07:21, 15 February 2024 (UTC)[reply]
Possibly, but before we get to that, let me start with the failed call above. I was trying to follow what MSGJ was telling me, but I think I made a mistake because it didn't work, so what did I do wrong? I don't absolutely need to have a template that works around it and am happy to invoke the Module alone, if I can get it to work. In the direct module invocation above, what am I doing wrong? I am not using the 'main', I'm using the getValue entry point but it still fails to return a value, because, if I understand correctly what the code near line 91 is doing, you cannot use getValue without a parameter name in arg3. Am I reading that right? Mathglot (talk) 07:34, 15 February 2024 (UTC)[reply]
main is simply a wrapper that provides the parameters from a frame into getValue. Yes, getValue itself will not run without a parameter to look for (which is arg 3 in a template invocation or parameter 2 in a module invocation), since that's a core part of the current functionality. I think MSGJ was probably talking about using it from a module perspective for getting false and the error message to return, as this isn't something you can currently do via a template invocation (see line 162). Aidan9382 (talk) 07:39, 15 February 2024 (UTC)[reply]