Thread:Extension talk:Cite/Solution: Template in refs and refs in templates

This may be handy for others. I wanted to create a ref template to add a reference and a refs template to create the footer automatically unless there were no refs. Usage:

per ref: footer:

The idea was to collect the references and set a variable refs which enables the footer. This requires Extension:ParserFunctions and Extension:Variables.

The following 2 templates - first attempt - did not work:

ref template:

refs template:

This fails because everything between the ref tags is collected until the references tag is called, and at this moment there are no more template arguments.

The following solution works - unfolded for better readability:

ref template:

refs template:

The ref template increments a variable i to define variables link0, text0, and on next call link1, text1, and sets the refs variable. The part within the ref tags contains a second loop counter for i for the references invocation and expands the variables correctly. The refs template just needs to reset the loop counter before the references tag is called.

This solution is template proof etc since the variables are defined at ref tag time.

Hope this is helpful for someone.