Forum:How to Transclude only once
ShoutWiki — express yourself and be heard!
Jump to navigation
Jump to search
Forums: Index → Community help
I have a template that uses ((Special:WhatLinksHere)). For reasons related to the purpose of the wiki, I use this template on pretty much every page.
The problem is that when I want to transclude any page that uses this template it takes the list of pages and the categories with it. I can solve this by going to every page I want to transclude and add NoInclude to it, but I'm wondering if tI can just edit the template itself to automatically add the NoInclude tag ABOVE ((Special:WhatLinksHere)) when it is transcluded, thus preventing whatever the template spits out (As well as the page-specific categories underneath it) from being transcluded as well.
Any ideas?
Mecheye (talk) 13:04, 27 June 2019 (UTC)
- Because of the way the parser works, it can't be done without a parser extension. Whenever there's a transclusion, the transclusion is parsed until there's nothing left to parse, then it's included in the output. You can write a template to put
<noinclude>
tags around transcluded text, but the tags themselves would be treated like text, not like tags, because by that point the parsing is done. For example, make a template that containsand transclude it. The transclusion is{{#tag:noinclude|something}}
<noinclude>something</noinclude>
(literally). You woulld have to convince the parser to re-parse the already-parsed markup, which could be very undesirable, considering everything else in the parsed markup is probably no longer valid markup.
There is a maximum expansion depth, which stops the parser from expanding templates that have been nested too deeply. You basically have to invent a parser extension that sets the maximum depth to 1 for a new tag, say<includeonce>
, so that anything deeper than 1 wouldn't execute (and ideally not generate an error, either). I'm not sure that would even be a simple extension to write. --Saftzie (talk) 17:42, 27 June 2019 (UTC)