0

I would like to include a 'Notes' section in a transcluded template only if there are footnotes in the text entered in the template. How can I create a conditional statement that will include the <h2>Notes</h2> header plus the <references group="lower-alpha" /> only if someone has actually created a footnote in this group?

I had this working in a template using two parameters, one called transcription where I entered text and could footnote it using named {{efn}}s. Then another parameter called footnotes where I entered a list of the named {{efn}}s along with the content of the note. Then I could use:

{{#if: {{{footnotes|}}}|
<h2>Notes</h2>
{{notelist|refs=
{{{footnotes|}}}
}}}}

But if I used too many <ref> tags within the {{efn}}s themselves, I would get errors.

I discovered today a line in the documentation that says, "Due to limitations in the MediaWiki software, do not use list defined footnotes that contain references."

So I need to switch to entering the content of the {{efn}} or <ref group="lower-alpha">, either way, directly into the text in the 'transcription' parameter.

I've made several different attempts to use {{#ifeq}} to determine if there are any footnotes in the lower-alpha group.

{{#ifeq: <references group="lower-alpha" />|||
<h2>Notes</h2>
<references group="lower-alpha" />}}
{{#ifeq: {{#tag:references group="lower-alpha"}}|||
<h2>Notes</h2>
<references group="lower-alpha" />}}

But this is not comparing the contents of <references group="lower-alpha" />, it's literally comparing the statement <references group="lower-alpha" />, which is not empty, so the result is always false.

Is there some way to determine if the contents of <references group="lower-alpha" /> is empty so I can use #ifeq? Or is there maybe an even better way to do all of this?

InSync
  • 4,851
  • 4
  • 8
  • 30

1 Answers1

0

The extension output is generated at a later stage of the page's parsing, and at that time all the #ifs and such were already parsed. So in that sense, what you're asking seems to be imppssible.

In principle, you might be able to use Lua's function mw.title.getContent to search the page's raw source and find ref tags. Although, this is error-prone and also wouldn't work for ref tags that come from a template.

A more reasonable alternative might be to hide the header by CSS in case the below section is empty. This would require the use of the CSS :has operator which should now be supported in most modern browsers, but as of today (April 2023) isn't enabled by default for Firefox users. There's also the issue of the header appearing in the page's Table of Contents.

Noam
  • 1,317
  • 5
  • 16