Jump to content

Template talk:RQ:Skelton Scottysshe Kynge

Page contents not supported in other languages.
Add topic
From Wiktionary, the free dictionary
Latest comment: 2 years ago by Sgconlaw in topic Issue with the template

Issue with the template

[edit]

@Benwing2: I wonder if you can have a look at this template and see what I'm missing. For some reason, if you look at the first example on the documentation subpage, the page number specified with |page=94 is not displaying properly – the page number doesn't appear, and "pages" instead of "page" is displayed. However, the Internet Archive URL linking to the page is correct. I've tested |pages= and it seems to work fine. The parameter |page2= in the template handles the display of the page number, but I have looked at it several times and can't see any mistake. Any idea what's wrong? Could it be an issue with the quotation module? — Sgconlaw (talk) 18:24, 14 June 2022 (UTC)Reply

@Sgconlaw You have the following template code:
|page2       = {{#if:{{{page|}}}{{{pageref|}}}{{{1|}}}
    | {{#ifexpr:{{{page|}}}{{{pageref|}}}{{{1|}}}>92|[{{{page|{{{1|}}}}}}]}}
  }}
|pages2      = {{#if:{{{page|}}}{{{pageref|}}}{{{1|}}}
    | {{#ifexpr:{{{page|}}}{{{pageref|}}}{{{1|}}}>92|[{{{pages|}}}]}}
  }}

What this does if |page= is given and is > 92, both |page2= and |pages2= (as passed to {{quote-book}}) get set to non-empty values; apparently |pages2= takes precedence. The value that's set as |pages2= here is [{{{pages|}}}], and because |pages= wasn't specified, you get [], which displays as a left bracket followed by a right bracket. I assume you mean to have the condition for |pages2= examine |pages= instead of {{{page|}}}{{{pageref|}}}{{{1|}}}? If so, you need to fix this both here and in the definition of |pages=, where the same thing occurs. Benwing2 (talk) 03:22, 16 June 2022 (UTC)Reply

@Benwing2: thanks for looking into this. This is rather odd behaviour for the |page2= and |pages2= parameters, isn’t it? Why doesn’t |page2= provide any output when a template gives it a value? And if an editor doesn’t provide any value for |pages2=, why should the module cause that parameter to display anything? — Sgconlaw (talk) 03:38, 16 June 2022 (UTC)Reply
@Sgconlaw The module is simply preferring |pages2= over |page2= if both are specified with non-empty values. I think this is the correct thing to do. Do you think both should appear in this case? The problem here is that |pages2= is being given a non-empty value even when |pages= isn't specified, which doesn't seem right. Let me know if this doesn't make sense. Benwing2 (talk) 04:08, 16 June 2022 (UTC)Reply
@Sgconlaw To clarify, I think you should change the template code to read like this:
|page2       = {{#if:{{{page|}}}{{{pageref|}}}{{{1|}}}
    | {{#ifexpr:{{{page|}}}{{{pageref|}}}{{{1|}}}>92|[{{{page|{{{1|}}}}}}]}}
  }}
|pages2      = {{#if:{{{pages|}}}
    | {{#ifexpr:{{{{pages|}}}>92|[{{{pages|}}}]}}
  }}

and a similar change for |page=/|para2=. Benwing2 (talk) 04:09, 16 June 2022 (UTC)Reply

@Benwing2: oh, I see what you mean. On the other hand, |pages= and |pages2= will always contain a value like 93–94, which will then cause {{#ifexpr:}} to throw an error. To avoid this, it looks like we have to test if the first two characters of the value of |pages= exceeds 92 … I didn’t think it’d be this complex! Essentially, the facsimile of the 16th-century text appears on pages 93–96, while the rest of the work is a 19th-century commentary about that text and its historical background. I was trying to change what the template displays depending on whether a user quotes from the facsimile directly or the rest of the work. — Sgconlaw (talk) 04:48, 16 June 2022 (UTC)Reply
@Sgconlaw: It seems to me it's not exactly the first two characters, but whatever appears before a hyphen, en dash or em dash. I think the following will work:
{{#if:{{{{{{page|}}}{{{pageref|}}}{{{1|}}}
   |{{#ifexpr:{{{page|}}}{{{pageref|}}}{{{1|}}}>92|{{#invoke:call|call|RQ:Skelton Scottysshe Kynge/facsimile}}|{{#invoke:call|call|RQ:Skelton Scottysshe Kynge/commentary}}}}
   |{{#if:{{{pages|}}}
      |{{#ifexpr:{{#invoke:string|gsub|{{{pages|}}}|[-–—].*$|}}>92|{{#invoke:call|call|RQ:Skelton Scottysshe Kynge/facsimile}}|{{#invoke:call|call|RQ:Skelton Scottysshe Kynge/commentary}}}}
      |{{#invoke:call|call|RQ:Skelton Scottysshe Kynge/facsimile}}
   }}
}}

What this does is:

  1. If |page=, |pageref= or |1= are defined, check if the value specified is > 92, if so, call a subtemplate {{RQ:Skelton Scottysshe Kynge/facsimile}} to display values associated with the facsimile; otherwise call a subtemplate {{RQ:Skelton Scottysshe Kynge/commentary}} to display values associated with the commentary.
  2. Otherwise, if |pages= is defined, chop off anything starting with a hyphen, en dash or em dash, and check if the resulting value is > 92, calling one or the other subtemplate as above.
  3. Finally, if there's no page number, call the facsimile subtemplate.

That way, you only have to put this logic in one place, and the subtemplates can be cleanly defined to just invoke {{quote-book}} with the appropriate values. BTW, the code {{#invoke:call|call|RQ:Skelton Scottysshe Kynge/facsimile}} uses Module:call, which is something I defined awhile ago to invoke another template, passing all parameters to that template without having to explicitly specify them all (the alternative would be something like {{RQ:Skelton Scottysshe Kynge/facsimile|author={{{author|}}}|page={{{page|}}}|pageref={{{pageref|}}}|footer={{{footer|}}}|...}}, which would be annoying to type). Benwing2 (talk) 05:18, 16 June 2022 (UTC)Reply

@Sgconlaw I fixed the template accordingly. Please take a look at the subtemplates {{RQ:Skelton Scottysshe Kynge/facsimile}} and {{RQ:Skelton Scottysshe Kynge/commentary}} and let me know if they are correct. Benwing2 (talk) 06:00, 17 June 2022 (UTC)Reply
@Benwing2: oh, thanks! I’ll have a look. — Sgconlaw (talk) 10:36, 17 June 2022 (UTC)Reply