Template talk:Cl

From Angelina Jordan Wiki
Revision as of 08:22, 3 September 2025 by Most2dot0 (talk | contribs) (Why ifeq: html encoding isn't the same)

Why ifeq

@Most2dot0: Am I missing something? Instead of using {{#ifeq:}} to test whether U+2063 has been passed in the 2nd parameter (which I assume is what you're doing, since there's a non-printing character in that location in the code), why not just use {{#if:}}, like so?

 {{#if:{{{1|}}}
  | {{#if: {{{2|}}} | [[{{{1}}}|{{{2}}}]] }}
 }}

Which can also be done this way:

 {{#if: {{both|{{{1|}}}|{{{2|}}}}} | [[{{{1}}}|{{{2}}}]] }} }}

AFAICT, U+2063 counts as whitespace, and hence would evaluate as false. - dcljr (talk) 21:42, 2 September 2025 (UTC)

I'm not very familiar with these template coding, so I asked ChatGPT for help. That works sometimes quite well, and sometimes it fails. So while I somewhat had the feeling that there must be a better solution, I was quite happy when I had one that worked for the problem at hand, as I'm still in a rapid prototyping phase. And thus postponed the final solution for a later point, also considering, that I might come up with other solutions inbetween that would eliminate the need for that template. So, what I really was trying to solve was, that if I generate a link to a page with the table generator, it could happen that the source field was not set in the JSON, or an empty string, and that led to mangled text in the table, like some "[|]" stuff. I asked ChatGPT for a template to solve that, but that did not work (maybe because non-proper use of {{#ifeq:}} vs {{#if:}}. The macro worked when used with plain text, but not when its argument was a <placeholder[1]> for a computed field in the table definition. After further discussing this with ChatGPT, it was my impression that this is caused because the template is evaluated before the Lua code is executed, and since "<placeholder[1]>" is a non-empty string, it did not solve my problem. Somehow we came to the conclusion, that returning a non-empty string with an missing array indication in form of a special character (choice was U+2063) could solve this, and it did. . So, if you'd know how to check reliably that an computed argument to a macro is empty, I'd happy to use a simpler solution, that could also eliminate that U+2063 generation in the Lua code. So I'll try your suggestion. --Most2dot0 (talk) 22:50, 2 September 2025 (UTC)
Ok, I tried your 2nd solution, and appart from it having two extra brackets (}}) at the end, it does work. So we can leave it for being the more general solution. However, eliminating the U+2063 did not work: If I returned an empty string ("") instead, there was again garbage displayed. So I reverted that in the module code. However, instead of U+2063 I might want to use to a different whitespace in the future, one that's less visible (in terms of taking space) when it's printed, any suggestions? --Most2dot0 (talk) 23:18, 2 September 2025 (UTC)
Oops, you're right: I had an extra "}}" in there.[sheepish grin] As for your other points/questions, I'm not familiar with module coding / Lua, and you're not familiar with template coding, so I'm not sure we will be able to figure this out between the two of us. You're probably right that the problem is related to when the template is being executed. I think there is a way of dealing with just this kind of situation, but I can't remember what it is. Maybe something to do with  {{#safesubst:}}?? I never got that far in my template coding skills. Maybe ChatGPT can figure something out if you include that term as a hint. - dcljr (talk) 03:29, 3 September 2025 (UTC)
I guess U+2063 is not whitespace, after all: {{is true|&#x2063}} ⇒ 1. It's non-printing, but not whitespace. In any case, as you said, you're just "prototyping", so you can just go back to what worked before.[grin] (BTW, the thinnest whitespace character is the "hair space", &hairsp;, if that helps. [[Foo|&hairsp;]]. There is a little invisible "redlink" there.) - dcljr (talk) 04:25, 3 September 2025 (UTC)
That's another twist: the HTML gets evaluated only by the browser, so &#x2063; is not the same to the template as the actual invisible separater (" "): {{is true|⁣}} ⇒ . So, as said, I think your code does the job for the workaround with returning a whitespace including the invisible separater, and it does it for any whitespace, which is an improvement. --Most2dot0 (talk) 08:22, 3 September 2025 (UTC)