Community Central
Community Central
No edit summary
(white-space is wrong.)
Line 794: Line 794:
   
 
:Wel I don't really understand myself what happend. But if I use an <nowiki>#switch</nowiki> code like in the example the collapse function will not work anymore. So there is something wrong the the ParserFuction. The code doesn't understand what to do if there is an <nowiki>#switch</nowiki> inside the class: <code><nowiki>class="navbox collapsible{{#switch:{{PAGENAME}}|Gremlin miner|Skully|Dead Knight|Zombie|Wolf|Imp|Gargoyle|Spidey|Medusa|Troll|Dragon|Vamp|Necromancer|Reap|Skully Archer|Lich|Little spidey|Mummy|Necromancer zombie|Goblin|Ghost|Nether Ghost|Cerberus=|#default=&nbsp;collapsed}}"</nowiki></code>--[[User:Jens Ingels|Jens Ingels]] ([[User talk:Jens Ingels|talk]]) 14:36, July 27, 2012 (UTC)
 
:Wel I don't really understand myself what happend. But if I use an <nowiki>#switch</nowiki> code like in the example the collapse function will not work anymore. So there is something wrong the the ParserFuction. The code doesn't understand what to do if there is an <nowiki>#switch</nowiki> inside the class: <code><nowiki>class="navbox collapsible{{#switch:{{PAGENAME}}|Gremlin miner|Skully|Dead Knight|Zombie|Wolf|Imp|Gargoyle|Spidey|Medusa|Troll|Dragon|Vamp|Necromancer|Reap|Skully Archer|Lich|Little spidey|Mummy|Necromancer zombie|Goblin|Ghost|Nether Ghost|Cerberus=|#default=&nbsp;collapsed}}"</nowiki></code>--[[User:Jens Ingels|Jens Ingels]] ([[User talk:Jens Ingels|talk]]) 14:36, July 27, 2012 (UTC)
  +
<!-- Please put your content under this line. Be sure to sign your edits with four tildes: ~~~~
 
  +
----
If you require staff help, please use Special:Contact or community@wikia.com to be sure of a staff reply. -->
 
  +
Put a space before the <code>#switch</code>. You are colliding the two classes together.
  +
<pre>{| class="navbox collapsible&lt;PUT A SPACE HERE&gt;{{#switch:{{PAGENAME}}|Gremlin miner|Skully|Dead Knight|Zombie|Wolf|Imp|Gargoyle|Spidey|Medusa|Troll|Dragon|Vamp|Necromancer|Reap|Skully Archer|Lich|Little spidey|Mummy|Necromancer zombie|Goblin|Ghost|Nether Ghost|Cerberus=|#default=&nbsp;collapsed}}</pre>
  +
The problem is that if your switch doesn't match anything then the <code>#default</code> will be used resulting in: <code>class="navbox collapsiblecollapsed"</code> (Notice how <code>collapsible</code> and <code>collapsed</code> are slammed together). The important thing to remember is that '''leading and trailing white-space is ignored by MediaWiki'''. The following 2 statements are identical:
  +
<pre>{{ SomeTemplate | Param1
  +
| someparameter = Param 2 }}</pre>
  +
<pre>{{SomeTemplate|Param1|someparameter=Param 2}}</pre>
  +
Only whitespace after the first non-white-space character is included in the result. Trailing white-space (after the last non-white-space character) is also thrown away. This feature is actually very useful since it lets you break your template and parser functions across multiple lines so you don't have to cram everything on one really really long line. This is very important for readability when you start doing complicated things like putting an <code>#if</code> inside a parameter to a template inside a <code>#switch</code> inside another <code>#switch</code>.
  +
  +
BTW, you can see the problem using Web Inspector in either Firefox or Chrome (or Developer Tools in Internet Explorer, maybe). If you inspect the table generated by your navbox template, you can see the contents of the <code>class</code> attribute on the <code>table</code> tag which helps make these sorts of problems reasonably obvious. [[User:Lunarity|Lunarity]] 16:04, July 27, 2012 (UTC)

Revision as of 16:04, 27 July 2012

Forums: Index Support Requests ParserFunctions support for ShowHide extension
Fandom's forums are a place for the community to help other members.
To contact staff directly or to report bugs, please use Special:Contact.
Archive
Note: This topic has been unedited for 4284 days. It is considered archived - the discussion is over. Information in this thread may be out of date. Do not add to unless it really needs a response.

I currently have some problems with an support of parserfunctions inside an collapse class. Here an example:

  • The page it showed: {{Navbox troops}}
  • Navbox troops template: {{Navbox units}}{{Navbox neutral}}{{Navbox heroes}}
  • Navbox units:
{| class="navbox collapsible{{#switch:{{PAGENAME}}|Gremlin miner|Skully|Dead Knight|Zombie|Wolf|Imp|Gargoyle|Spidey|Medusa|Troll|Dragon|Vamp|Necromancer|Reap|Skully Archer|Lich|Little spidey|Mummy|Necromancer zombie|Goblin|Ghost|Nether Ghost|Cerberus=|#default= collapsed}}" style="width:100%; margin-top:1em; border:1px solid #999; font-size:90%; text-align:center;"
|-
! style="background-color:#FF0000; color:#000000; padding:0.2em 0.5em;" nowrap="nowrap"|<div style="text-indent: 10%;">Units</div>
|-
| style="padding:0.2em 0.5em;"| '''[[:Category:Passive units|Passive]]''': [[Gremlin miner]]<br />'''[[:Category:Melee units|Melee]]''': [[Skully]] · [[Dead Knight]] · [[Zombie]] · [[Wolf]] · [[Imp]] · [[Gargoyle]] · [[Spidey]] · [[Medusa]] · [[Troll]] · [[Dragon]]<br />'''[[:Category:Mid range units|Mid range]]''': [[Vamp]] · [[Necromancer]] · [[Reap]]<br />'''[[:Category:Long range units|Long range]]''': [[Skully Archer]] · [[Lich]]<br />'''[[:Category:Summoned units|Summoned]]''': [[Little spidey]] · [[Mummy]] · [[Necromancer zombie]] · [[Goblin]] · [[Ghost]] · ([[Nether Ghost]])<br /><br />'''Unknown''': ([[Cerberus]])
|}

The other 2 are similar. Now is the question why it doesn't work. I currently removed the full common.js and testing on the userstyle. My user style:


And here's the css:


And here is the wikia.css:


Other notes are the the toggler extension also is installed like you can see with the user style js here is the code:

And last not least the showhide code. I only replace all names to + and - and removed the []

Finaly the old commons you can find here and here. If you known an fix please tell me.--Jens Ingels (talk) 13:11, July 27, 2012 (UTC)

I'm a little confused. What exactly isn't working? -- RandomTime 13:21, July 27, 2012 (UTC)
Wel I don't really understand myself what happend. But if I use an #switch code like in the example the collapse function will not work anymore. So there is something wrong the the ParserFuction. The code doesn't understand what to do if there is an #switch inside the class: class="navbox collapsible{{#switch:{{PAGENAME}}|Gremlin miner|Skully|Dead Knight|Zombie|Wolf|Imp|Gargoyle|Spidey|Medusa|Troll|Dragon|Vamp|Necromancer|Reap|Skully Archer|Lich|Little spidey|Mummy|Necromancer zombie|Goblin|Ghost|Nether Ghost|Cerberus=|#default= collapsed}}"--Jens Ingels (talk) 14:36, July 27, 2012 (UTC)

Put a space before the #switch. You are colliding the two classes together.

{| class="navbox collapsible<PUT A SPACE HERE>{{#switch:{{PAGENAME}}|Gremlin miner|Skully|Dead Knight|Zombie|Wolf|Imp|Gargoyle|Spidey|Medusa|Troll|Dragon|Vamp|Necromancer|Reap|Skully Archer|Lich|Little spidey|Mummy|Necromancer zombie|Goblin|Ghost|Nether Ghost|Cerberus=|#default= collapsed}}

The problem is that if your switch doesn't match anything then the #default will be used resulting in: class="navbox collapsiblecollapsed" (Notice how collapsible and collapsed are slammed together). The important thing to remember is that leading and trailing white-space is ignored by MediaWiki. The following 2 statements are identical:

{{     SomeTemplate    |    Param1
     | someparameter = Param  2     }}
{{SomeTemplate|Param1|someparameter=Param  2}}

Only whitespace after the first non-white-space character is included in the result. Trailing white-space (after the last non-white-space character) is also thrown away. This feature is actually very useful since it lets you break your template and parser functions across multiple lines so you don't have to cram everything on one really really long line. This is very important for readability when you start doing complicated things like putting an #if inside a parameter to a template inside a #switch inside another #switch.

BTW, you can see the problem using Web Inspector in either Firefox or Chrome (or Developer Tools in Internet Explorer, maybe). If you inspect the table generated by your navbox template, you can see the contents of the class attribute on the table tag which helps make these sorts of problems reasonably obvious. Lunarity 16:04, July 27, 2012 (UTC)