FANDOM


  • I'm trying to get this Infobox template I've create to display links to subpages automagically, but the code below doesn't seem to do the deed. Where did I goof?

    {{#ifeq: {{#expr: {{#ifexist: {{PAGENAME}}/Mobs|1|0}} or {{#ifexists: {{PAGENAME}}/Shops|1|0}} }}|1|! colspan="2" style="background-color:#3366CC; color:#ffffff;" {{!}} Additional info {{!}}- {{#ifexist: {{PAGENAME}}/Mobs|{{!}} colspan="2" {{!}}[[/Mobs|List of mobs]] {{!}}-}} {{#ifexist: {{PAGENAME}}/Shops|{{!}} colspan="2" {{!}}[[/Shops|List of shops]] {{!}}-}}}}

      Loading editor
    • For one thing "or" doesn't work for wikitext code. You should probably read Help:Extension:ParserFunctions much more carefully and try again.

      I will give you a hint. If you want to display a link to {{PAGENAME}}/Mobs, just do something like this:

      {{#ifexist:{{PAGENAME}}/Mobs|[[{{PAGENAME}}/Mobs]]}}
      
        Loading editor
    • Please note the #ifexist is considered an expensive parser function and each page has a limit to the number of expensive parser functions that can be used. Also, if the page you are checking for doesn't exist, it will be added to the list of wanted pages; even if it isn't supposed to exist.


      Edit:

      Fandyllic, the "or" is in the expression for #expr which does support it.

        Loading editor
    • Fandyllic wrote: For one thing "or" doesn't work for wikitext code. You should probably read Help:Extension:ParserFunctions much more carefully and try again.

      Just one problem, it is evaluating numbers, either two 0s, one 1 and one 0, or two 1s.

      I will give you a hint. If you want to display a link to {{PAGENAME}}/Mobs, just do something like this:

      {{#ifexist:{{PAGENAME}}/Mobs|[[{{PAGENAME}}/Mobs]]}}
      

      Which is exactly what the code is…

        Loading editor
    • Andrewds1021 wrote: Please note the #ifexist is considered an expensive parser function and each page has a limit to the number of expensive parser functions that can be used. Also, if the page you are checking for doesn't exist, it will be added to the list of wanted pages; even if it isn't supposed to exist.

      I know, and it's of no problem. There's only these two subpages to check for anyway. And for those few instances where the shop page are not suppose to exist the listing in Wanted Pages are of no consequence anyway. It isn't as anyone are going to check the Special Pages anyway. The majority of users are completely wikimarkup illiterate anyway.

        Loading editor
    • So looking at the template more closely it looks like the problem is related to the row start wikitext (|-) being part of the a previous #if block and so may not show when needed.

      Current code:

      {{#if: {{{fountain|}}}|{{!}} colspan="2" {{!}}This zone contains a drinking fountain
      {{!}}-}}
      {{#ifexist: {{PAGENAME}}/Mobs|{{!}} colspan="2" {{!}}[[/Mobs|List of mobs]]
      {{!}}-}}
      {{#ifexist: {{PAGENAME}}/Shops|{{!}} colspan="2" {{!}}[[/Shops|List of shops]]
      {{!}}-}}
      

      The code above has the problem that the row start (|-) for {{PAGENAME}}/Mobs may only appear if {{{fountain}}} is used.

      Would work better like this (move the row starts out of the #if or ifexist):

      {{!}}-
      {{#if: {{{fountain|}}}|{{!}} colspan="2" {{!}}This zone contains a drinking fountain}}
      {{!}}-
      {{#ifexist: {{PAGENAME}}/Mobs|{{!}} colspan="2" {{!}}[[/Mobs|List of mobs]]}}
      {{!}}-
      {{#ifexist: {{PAGENAME}}/Shops|{{!}} colspan="2" {{!}}[[/Shops|List of shops]]}}
      

      A row start without a cell shol not display anything, so it should be safe to not have the row starts inside if blocks.

        Loading editor
    • Fandyllic wrote: So looking at the template more closely it looks like the problem is related to the row start wikitext (|-) being part of the a previous #if block and so may not show when needed.

      Current code:

      {{#if: {{{fountain|}}}|{{!}} colspan="2" {{!}}This zone contains a drinking fountain
      {{!}}-}}
      {{#ifexist: {{PAGENAME}}/Mobs|{{!}} colspan="2" {{!}}[[/Mobs|List of mobs]]
      {{!}}-}}
      {{#ifexist: {{PAGENAME}}/Shops|{{!}} colspan="2" {{!}}[[/Shops|List of shops]]
      {{!}}-}}
      

      The code above has the problem that the row start (|-) for {{PAGENAME}}/Mobs may only appear if {{{fountain}}} is used.

      The code works, although it wasn't what I was hoping for. The problem with the current code is that the heading "Additional information" is displayed regardless of the presence of any additional information. I would prefer that the heading was only displayed if at least one of the options was used, or one of the subpages was present

        Loading editor
    • It works, but maybe not well... the conditions for showing "Addition information" should be achievable.

      You may want to switch to the new portable infobox style.

        Loading editor
    • The you need to place the header in an "if" or "ifexist" function as well. It would be easier to use "if" but then, as you know, that won't check to see if the page is actually used.

      {{#if: {{{param1|}}}{{{param2|}}}{{{param3|}}}
      | if param1 or param2 or param3 has a non-whitespace value
      | if none of the parameters have a non-whitespace value
      }}
      
        Loading editor
    • Fandyllic wrote: It works, but maybe not well... the conditions for showing "Addition information" should be achievable.

      Works quite well, actually. As for the conditions, that's why I wanted to use #expr: for logical or.

      You may want to switch to the new portable infobox style.

      I don't think the new portable infobox would work any better. It requires the same kind of code to do its job properly too.

        Loading editor
    • Portable infobox markup has better specific code for showing or hiding headers based on groups of items, but I'm no expert.

        Loading editor
    • Fandyllic wrote: Portable infobox markup has better specific code for showing or hiding headers based on groups of items, but I'm no expert.

      I rather keep to something that is known to work, than an experimental new thing that still has to prove itself

        Loading editor
    • Andrewds1021 wrote: The you need to place the header in an "if" or "ifexist" function as well. It would be easier to use "if" but then, as you know, that won't check to see if the page is actually used.

      {{#if: {{{param1|}}}{{{param2|}}}{{{param3|}}}
      | if param1 or param2 or param3 has a non-whitespace value
      | if none of the parameters have a non-whitespace value
      }}
      

      Thank you for solving the problem. Here's the final code:

      {{#if: {{{quest|}}}{{{bulletinboard|}}}{{#ifexist: {{PAGENAME}}/Mobs|1}}{{#ifexist: {{PAGENAME}}/Shops|1}}|! colspan="2" style="background-color:#3366CC; color:#ffffff; text-align:center;" {{!}} Additional info
      {{!}}-
      {{#if: {{{quest|}}}|{{!}} colspan="2" {{!}}This zone contains one or more quests[[Category:Quest Zone]]
      {{!}}-
      {{#if: {{{questoutside|}}}|{{!}} colspan="2" {{!}}One or more of the quests require items from outside this zone
      {{!}}-}}}}
      {{#if: {{{bulletinboard|}}}|{{!}} colspan="2" {{!}}This zone has a bulletin board
      {{!}}-}}
      {{#if: {{{fountain|}}}|{{!}} colspan="2" {{!}}This zone contains a drinking fountain
      {{!}}-}}
      {{#ifexist: {{PAGENAME}}/Mobs|{{!}} colspan="2" {{!}}[[/Mobs|List of mobs]]
      {{!}}-}}
      {{#ifexist: {{PAGENAME}}/Shops|{{!}} colspan="2" {{!}}[[/Shops|List of shops]]
      {{!}}-}}}}
      
        Loading editor
    • to hide/show the subpage links, yes the code is the same. However, the portable infobox code will do all the size, float right, etc. for you rather than needing the explicitly add all that to a table. It will also auto-hide any unused data fields/groups so you wouldn't need to use #if just to hide the header. Also, it will automatically adjust the layout for viewing on mobile.

        Loading editor
    • Andrewds1021 wrote: to hide/show the subpage links, yes the code is the same. However, the portable infobox code will do all the size, float right, etc. for you rather than needing the explicitly add all that to a table. It will also auto-hide any unused data fields/groups so you wouldn't need to use #if just to hide the header. Also, it will automatically adjust the layout for viewing on mobile.

      In other words, you lose all control and have to rely on someone else's programming skills… I don't think so

        Loading editor
    • Glad you got a solution you like.

      For future reference, Portable infoboxes do require you to learn something new, but they are far better on mobile and over half of all wiki visitors come via mobile, so having mobile friendly pages is an advantage.

        Loading editor
    • When Fandom says that, they obviously are referring to either Fandom as a whole or the "average" wiki. I can tell you that the majority of views for "my" wiki don't come from mobile.

        Loading editor
    • Fandyllic wrote: Glad you got a solution you like.

      For future reference, Portable infoboxes do require you to learn something new, but they are far better on mobile and over half of all wiki visitors come via mobile, so having mobile friendly pages is an advantage.

      I cannot verify those claims. The infoboxes looks fine on my mobile

        Loading editor
    • You don't need to... portable infoboxes have been around a long time and used on far more complex infoboxes than yours.

      Like I said, it is just for reference.

        Loading editor
    • A FANDOM user
        Loading editor
Give Kudos to this message
You've given this message Kudos!
See who gave Kudos to this message
Community content is available under CC-BY-SA unless otherwise noted.