FANDOM


  • I'm creating a template that will use images to link to 1 or 2 other wikis on the platform. The template will be called by:

    Example 1: {{TemplateName|wiki1|wiki2}}

    or

    Example 2: {{TemplateName|wiki1=PageABC|wiki2=PageXYZ}}

    The parameters "wiki1" and "wiki2" should link to the page on those other wikis based on the value of the parameter. If no value is set (ie. Example 1), the link should be based on the pagename of my wiki.

    This is what I have so far:

    {{#if:{{{wiki1|}}}|[[File:Image1.png|link=w:c:wiki1Name:{{{wiki1}}}]]}}{{#if:{{{wiki2|}}}|[[File:Image2.png|link=w:c:wiki2Name:{{{wiki2}}}]]|}}

    At this point, it is properly linking to the appropriate wiki based on the parameters' values (ie. Example 2 works).

    Now I need to extend the template to support when no value is added (ie. Example 1). If I understand right, by not including values to the parameters, it's not creating an actual parameter, but instead assigning a value to {{{1}}} and {{{2}}}. So, I'm having trouble incorporating this functionality into what I have. I know it will end up using {{PAGENAME}}.

    It also needs to support circumstances where:

    1. Only one of the parameters is included, ex. {{TemplateName|wiki2}} properly links to w:c:wiki2Name.
    2. One parameter is set and the other is just included, ex. {{TemplateName|wiki1=PageABC|wiki2}} or vice-versa. Both linking to their correct wiki.
      Loading editor
    • Hello!

      Actually, you don't even need the #if function, only to work with default values of the parameters:

      [[File:Image1.png|link=w:c:wiki1Name:{{{wiki1|{{{1|{{PAGENAME}}}}}}}}]]
      [[File:Image2.png|link=w:c:wiki2Name:{{{wiki2|{{{2|{{PAGENAME}}}}}}}}]]

      (This would work only for main pages. If you are using it in other pages, for example to link between profile pages of the same user, use {{FULLPAGENAME}} instead.

      For the last part:

      1. In case the user gives only one unnamed parameter, it will be associated to 1, of course. Otherwise, how can you know what did the user mean?

      2. You can do it, though it'll complicate the code a bit. I can't put it now but I'll do it later. Notif here if I forget.

        Loading editor
    • So actually, if you want to handle weird inputs, there can be a lot of them, each one needs to be handled seperately. But let's focus in the two cases you mentioned.

      The case of {{TemplateName |PageInWiki1 |wiki2=PageInWiki2}} is already covered in the code above. The problematic case is {{TemplateName |wiki1=PageInWiki1 |PageInWiki2}}. Also {{TemplateName |PageInWiki2 |wiki1=PageInWiki1}} is the same for us, there is no way to know whether the unnamed patameter was provided before or after the named one.

      Anyway:

      {{#ifexpr:{{#if:{{{wiki1|}}}|1|0}} and {{#if:{{{wiki2|}}}|0|1}} and {{#if:{{{1|}}}|1|0}} 
        |[[File:Image1.png|link=w:c:wiki1Name:{{{wiki1}}}]]
      [[File:Image2.png|link=w:c:wiki2Name:{{{1}}}]]
        |[[File:Image1.png|link=w:c:wiki1Name:{{{wiki1|{{{1|{{PAGENAME}}}}}}}}]]
      [[File:Image2.png|link=w:c:wiki2Name:{{{wiki2|{{{2|{{PAGENAME}}}}}}}}]]
      }}
      

      I should say, I didn't test the code and can't promise no bugs or just syntax mistakes. If there are, you are welcome to ask for help fixing it.

        Loading editor
    • I believe this is what you would want instead of the wikitext in #3.

      [[File:Image1.png|link=w:c:wiki1Name:{{{wiki1|{{{1|{{PAGENAME}}}}}}}}]]
      [[File:Image2.png|link=w:c:wiki2Name:{{{wiki2|{{#if:{{#if:{{{wiki1|}}}||a}}{{#if:{{{1|}}}||a}}|{{{2|{{PAGENAME}}}}}|{{{1}}}}}}}}]]
      

      That said, I think doing into this level of detail is superfluous.

        Loading editor
    • Andrew, I can't get your condition statement. It seems to say:

      IF wiki1 is not empty OR 1 is not empty

      THEN 2|PAGENAME

      ELSE 1 (no option to PAGENAME)


      While we need:

      IF wiki1 is not empty AND 1 is not empty

      THEN 1

      ELSE 2|PAGENAME


      Although you are right in shortening it. Maybe:

      [[File:Image1.png|link=w:c:wiki1Name:{{{wiki1|{{{1|{{PAGENAME}}}}}}}}]]
      [[File:Image2.png|link=w:c:wiki2Name:{{{wiki2|{{#ifeq:{{#if:{{{wiki1|}}}||a}}{{#if:{{{1|}}}||a}}|aa|{{{1}}}|{{{2|{{PAGENAME}}}}}}}}}}]]
      


      Also you are right all of this is unnecessary...

        Loading editor
    • #ifeq is not correct since we are testing for either "a" or "aa". A fallback to PAGENAME in the second code block is not needed as that part will be used only if both wiki1 and 1 are both not empty.

      {{#if:{{{1|}}}||a}}{{#if:{{{2|}}}||a}}
      

      This produces "a" if one of the parameters is empty and "aa" if both parameters are empty.

      {{#if: {{#if:{{{1|}}}||a}}{{#if:{{{2|}}}||a}}
      | b
      | c
      }}
      

      As such, this produces "b" if either or both parameters are empty and produces "c" when both parameters are not empty.

      I hope that makes sense.

        Loading editor
    • Well, Andrew is way more exprienced than me, yet I'm afraid in this case he put the right code for the wrong algorithm. (Or I am missing something else...)

      @Random_User123, you are welcome to test both codes, and to ask for additional help if you need (may be on my wall if you want).

        Loading editor
    • Thank you both. I will be looking closer to your replies and testing the suggestions soon. Just got unexpectedly busy after posting, but I'm certainly not abandoning the thread. When you guys say this level of detail is unnecessary, are you saying it in regard to my circumstances or in how the code it setup? If there is a cleaner way to approach it, I'm interested.

      It's just that there are a mix of situations and the template would ideally cover them all. If I use {{TemplateName|wiki2}} on a page, it's setting {{{1}}} to "wiki2", but the link needs to go to wiki2Name. There would be no intended link to wiki1Name in that situation. Maybe I should just stick with my Example 2 on all pages, even if the pagenames across the three wikis is the same. When I get time again (hopefully this weekend), I'll look closer to your suggestions.

        Loading editor
    • I'm realizing it's actually unclear what exactly do you want to happen in each case, probably that's what caused the different answers.

        Loading editor
    • Random User123, based on the second paragraph in your reply, I think you might be confused about how template parameters work.

      {{Example|wiki2}}
      

      This passes in the text "wiki2" as the value for parameter "1". It does not signal to show only parts of the template that use parameter "wiki2".

        Loading editor
    • Thanks, but isn't that what I said, even in the OP? That's why I thought I needed IF statements, because wiki1 or wiki2 may not always be there, either as named parameters, or as values to {{{1}}} and {{{2}}} (positional parameters). One of them will always be there, but it's unknown which it will be, whether it's a named parameter or positional, and what order they'll be in if both are present. The issue is when "wiki2" becomes a value of {{{1}}} because it needs to link to "w:c:wiki2Name".

      Here's a list of use cases:

      1. |wiki1
      2. |wiki1=PageABC
      3. |wiki2
      4. |wiki2=PageXYZ
      5. |wiki1|wiki2
      6. |wiki2|wiki1
      7. |wiki1=PageABC|wiki2
      8. |wiki2|wiki1=PageABC
      9. |wiki1|wiki2=PageXYZ
      10. |wiki2=PageXYZ|wiki1
      11. |wiki1=PageABC|wiki2=PageXYZ
      12. |wiki2=PageXYZ|wiki1=PageABC

      • Cases 2, 4, 11-12 are fine because all stuff included in the template are named parameters. I just use the right parameter & value where I want it.
      • Cases 1, 5, 9-10 are also fine because {{{1}}} = "wiki1". I can make {{{1}}} default link to "wiki1Name". If {{{2}}} exists (case 5), it would link to "wiki2Name".
      • Case 6 isn't an issue because both {{{1}}} and {{{2}}} link to their respective wikis using PAGENAME anyway.
      • Cases 3, 7-8 are the issue because {{{1}}} = "wiki2".

      What I believe I need to do is check if {{{1}}} = "wiki2" and then link it to "w:c:wiki2Name:{{PAGENAME}}".


      Before posting the above (and after rewriting it because this forum system lost the reply), I think I came up with the solution. Each line is in a bullet for easier reading:

      • {{#if:{{{wiki1|}}}|[[File:Image1.png|link=w:c:wiki1Name:{{{wiki1}}}]]|}}
      • {{#ifeq:{{{1}}}|wiki1|[[File:Image1.png|link=w:c:wiki1Name:{{PAGENAME}}]]|}}
      • {{#ifeq:{{{2}}}|wiki1|[[File:Image1.png|link=w:c:wiki1Name:{{PAGENAME}}]]|}}
      • {{#if:{{{wiki2|}}}|[[File:Image2.png|link=w:c:wiki2Name:{{{wiki2}}}]]|}}
      • {{#ifeq:{{{1}}}|wiki2|[[File:Image2.png|link=w:c:wiki2Name:{{PAGENAME}}]]|}}
      • {{#ifeq:{{{2}}}|wiki2|[[File:Image2.png|link=w:c:wiki2Name:{{PAGENAME}}]]|}}

      It appears to work for all 12 use cases, but I'm going to verify it this weekend with fresh eyes. If you guys have any suggestions on how I can reduce the template code w/o losing functionality, I would appreciate it. I also appreciate the effort thus far nonetheless.

        Loading editor
    • Yes, if you want to support {{Example|wiki1}} as an alternative to {{Example|wiki1=}}, then you need to use #eq as well. to be honest though, this is highly unusual use of a template parameter. I have never seen a wiki use templates like this before.

        Loading editor
    • Also for some inputs, the multiple #if statements will end up with duplicates of the same image, either linking to the same page or to different pages. This can be handled too but with additional complexity. And you are throwing off the simple usage of {{Template |PageABC |PageXYZ}}.

      Neverthless, if you still need, I'll be happy to help you with whatever you want it to do.

        Loading editor
    • Hi

        Loading editor
    • Andrewds1021 wrote:
      Yes, if you want to support {{Example|wiki1}} as an alternative to {{Example|wiki1=}}, then you need to use #eq as well.

      Yea, I want to support {{Template1|wiki1}} because it's short and easiest for editors to understand. {{Template1|wiki1=}} does nothing in my test, which is fine, too. From an editor's perspective, they're either including their own page title for the link to go to, or they're not and having the link default to the current PAGENAME.

      HumansCanWinElves wrote:
      Also for some inputs...

      If a user adds multiple, like {{Template1|wiki1|wiki1=PageABC}} than that would be an incorrect use of the template and I'd correct it. {{Template1|PageABC3|PageXYZ3}} would also be incorrect use and doesn't display anything, which is also perfect.

      Perhaps I can add a check to verify the named & positional parameters are being used correctly, aren't duplicates, missing, etc. Then I can quickly identify which pages need to fix use of the template.

        Loading editor
    • OK I think that now I get what you do want. You don't want the links to both wikis to appear anyway, you want the user to be able to create a link only to wiki1 or only to wiki2, that's why you use the text wiki1 or wiki2 as a parameter.

      To avoid duplicates, you can nest the conditions, so each condition will be referred only in case the previous one evaluated as false:

      {{#if:{{{wiki1|}}}|[[File:Image1.png|link=w:c:wiki1Name:{{{wiki1}}}]]
        |{{#ifeq:{{{1}}}|wiki1|[[File:Image1.png|link=w:c:wiki1Name:{{PAGENAME}}]]
           |{{#ifeq:{{{2}}}|wiki1|[[File:Image1.png|link=w:c:wiki1Name:{{PAGENAME}}]]|}}
         }}
      }}
      
      {{#if:{{{wiki2|}}}|[[File:Image2.png|link=w:c:wiki2Name:{{{wiki2}}}]]
        |{{#ifeq:{{{1}}}|wiki2|[[File:Image2.png|link=w:c:wiki2Name:{{PAGENAME}}]]
           |{{#ifeq:{{{2}}}|wiki2|[[File:Image2.png|link=w:c:wiki2Name:{{PAGENAME}}]]|}}
         }}
      }}
      
        Loading editor
    • HumansCanWinElves wrote:
      You don't want the links to both wikis to appear anyway, you want the user to be able to create a link only to wiki1 or only to wiki2

      No, these are inter-wiki links displayed as icons that appear above an infobox. Think of it like a wiki dedicated to the T.V. show Cheers, and then another to its spinoff Frasier. Similar topics, but big enough to be separate wikis. Some characters are featured in one show and then brought up in the other, so you link the articles with the little icon at the top. The wikis can have a page on a specific character, but they're independent wikis and the page names don't need to match. That's easy enough when one wiki is linking to only another: {{Template1|[[File:Image.png|link=w:c:wikiName:{{{1|{{PAGENAME}}}}}]]}}

      But how about a topic large enough to warrant 3+ independent wikis, like a video game series? They may have similar characters, items, locations, etc., but each wiki is informative from that wiki-topic's perspective. Each one may have a page on a character, but each may title the page differently, especially if the character changes their name over the series. So, a template to add multiple inter-wiki link-icons. If the template is to be used, it will always have either:

      • Single icon to wiki1
      • Single icon to wiki2
      • Single icon each to wiki1 and wiki2 (and wiki1's icon always appears before wiki2's icon)

      The wikis already link to each other, but do it using 2 templates each (when applicable), and each template is setup like I mentioned in paragraph 1. I'm basically combining the two templates into one, but that complicates the template code because I need to ensure positional parameters display the appropriate link to the appropriate wiki. The reason I'm making this "master inter-wiki template" is because it allows me to format, align, and otherwise change the images/links as a single unit rather than editing 2 templates (or more down the road). It also simplifies it for other article editors, dealing with 1 template rather than 2. Plus, one of these templates is poorly named and I'd rather not go through thousands of pages to change the template name, even if via bot. I also So, I created this master inter-wiki template.

      In my solution, I forgot that each image has a tooltip and forced size parameter. Both images use the same image resize but slightly different tooltip messages.

      • {{#if:{{{wiki1|}}}|[[File:Image1.png|link=w:c:wiki1Name:{{{wiki1}}}|View the wiki1Name article on: {{FULLPAGENAME}}|x30px]]|}}

      I was thinking of using variables to shrink the code down more, especially since the file portions of lines 2-3 are exactly the same, as are lines 5-6.

        Loading editor
    • Variables are an extesion you have to install on your wiki, but I think it's not needed in this case. Here is a shrinked version, including the caption and resizing, though I'm not sure if I got right what do you want the caption to say:

      [[File:Image1.png|View the wiki1Name article on:{{FULLPAGENAME}}|x30px|
      {{#if:{{{wiki1|}}}|link=w:c:wiki1Name:{{{wiki1}}}
        |{{#ifeq:{{{1}}}|wiki1|link=w:c:wiki1Name:{{PAGENAME}}
           |{{#ifeq:{{{2}}}|wiki1|link=w:c:wiki1Name:{{PAGENAME}}]]|}}
         }}
      }}]]
      
      [[File:Image2.png|View the wiki2Name article on: {{FULLPAGENAME}}|x30px|
      {{#if:{{{wiki2|}}}|link=w:c:wik21Name:{{{wiki1}}}
        |{{#ifeq:{{{1}}}|wiki2|link=w:c:wiki2Name:{{PAGENAME}}
           |{{#ifeq:{{{2}}}|wiki2|link=w:c:wiki2Name:{{PAGENAME}}]]|}}
         }}
      }}]]
      
        Loading editor
    • Thank you. I'll give it a try when I can and let you know. That caption is fine. I also already got the variables extension if need be, but it'll be nicer if it's not.

        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.