3

In MediaWiki, is there a standard pattern that you can include in a template body to detect depth of transclusion?

Specifically, let's assume Template:Myinfobox contains such a pattern that displays "native myinfobox call" for depth 1 transclusion and "transclusion call" otherwise.

Then, if page Mypage calls {{Myinfobox}} it should display "native myinfobox call" while any page that calls {{Mypage}} should display "transclusion call"

Does anyone know such a pattern that does not require the writer of Mypage to insert special markup or <noinclude> or <includeonly> tags?

Ilmari Karonen
  • 49,047
  • 9
  • 93
  • 153
JR Bouvier
  • 31
  • 2

2 Answers2

1

Thanks for the pointers. I was aware of these but it's good to have them here. Right now I'm resorting to the following trick (using the terminology of my question): I have a home article parameter in the Myinfobox that the user of the template must set to the name of the page hosting the Myinfobox direct call. Thus Mypage will contain something like:

{{ Myinfobox | … | home article = Mypage | … }}

The Myinfobox template tests whether {{PAGENAME}} equals {{{ home article }}} to determine the message it outputs: "transclusion" in case the 2 values are different, "native" otherwise.

But this is clumsy and places burden on the template user.

  • Ah, that's indeed one way we do it, for instance in [`{{langcat}}`](https://www.mediawiki.org/wiki/Template:Langcat). – Nemo May 01 '15 at 11:14
0

No, there is no such thing. However, you can learn some evil tricks and internals on expansion depth limits and branching at

Nemo
  • 2,441
  • 2
  • 29
  • 63