Forum:Template Coding Help: If A exists, go A. Otherwise B.

Hello. I'm currently helping a wiki site at http://evchk.wikia.com/ (a Chinese wiki).

I have only shallow knowledge about wiki template coding. I have a question regarding a template Zhwiki.

This is what I want to achieve:

Plan A:
 * If our wiki (that is http://evchk.wikia.com/ ) has an article on this item, link to it: |}}
 * Otherwise, link to the famous Chinese Wikipedia's if it has an article on it:
 * Otherwise, just create a non-existing link of the item pointing to our wiki: |}}

UPDATED (Since someone says Plan A is mission impossible, what about Plan B?)

Plan B:
 * If our wiki (that is http://evchk.wikia.com/ ) has an article on this item, link to it: |}}
 * Otherwise, link to the famous Chinese Wikipedia's:

You can also specify the name of the intra-link:
 * Put and you get IP address.
 * Put and you get IP (linking to IP address).

By the way, are there any tools/ways available to preview the effect of the template first before putting in real use? I'm usually afraid I made a mistake in template coding and mess this template up. Also is there any dummy guide available to learn wiki template coding? --Comeon 12:07, 11 February 2009 (UTC)


 * Not possible that I know of, unfortunately. The 2nd step is the deal breaker, since we have no way to know what is or is not on Wikipedia. --Sky (talk) 14:36, 11 February 2009 (UTC)


 * What if I slightly changed the content, that is, Plan B (see above)? Something is better than nothing. --Comeon 23:25, 11 February 2009 (UTC)


 * The second is easily doable, but requires an expensive parser call (see more), which means it can only be included so many times on a page before the page breaks. Plan A would also have required this step. The coding would be:

{{#ifexist:{{{1|}}}
 * |
 * {{{2|{{{1}}}}}}

That said, wouldn't it be better if your wiki filled out instead; i.e., red links to be filled?... As for dummy guide, not really. There is a help wikia, as well as mediawiki.org for most documentation. --Sky (talk) 00:03, 12 February 2009 (UTC)


 * Sorry for the very late reply. I have edited the above code to fix minor bugs. I have one idea to partly relieve the server burder.

{{#ifexist:{{{1|}}} }}
 * Output (Subst) the result of "{{{2|{{{1}}}}}}"
 * {{{2|{{{1}}}}}}

Note: No more than 100 (inclusive) expensive parser call.

What code should I put so the code will be SUBST-ed (i.e. automatic conversion of wikitexts) if the first condition is matched, in other words, no further "ifexist" call will be made.

PS: Some people say they hate to see red links. That's why such workaround. --Comeon 06:40, 22 March 2009 (UTC)

PPS: Fixed the missing closing tag.--Comeon 07:29, 23 March 2009 (UTC)


 * The code above is missing  at the end. Now if i recall well
 * we will name this template as Template:A you are going to put this code
 * and when you use the template will be like.
 * and when you use the template will be like.


 * This way template:A will get substitute copying every thing except the  tags then simultaneously it will substitute the ifexist giving leaving only the end result interwiki link or wikipedia link. --{{User:Cizagna/Sig.css|14:02, 22 March 2009 (UTC)}}

If I understand correctly, it will be SUBSTed no matter what condition it meets. I ONLY want it to be SUBSTed if it meets the first condition (i.e. we have the internal links). Otherwise it should recheck every now and then (i.e. not SUBSTed).--Comeon 07:29, 23 March 2009 (UTC)
 * there is no way you can set it to subst the way you are requesting it. because when you're substituting the exists function operation and that operation will answer A or B and save A or B and the operation will be lost.
 * Now what you can do is if you know the page does not exists then just type  but you will have to come later and add the subst, but if i understand you are planing to heavily use it so i dont recommend the leave it as a template because will be any way painful manual labor --{{User:Cizagna/Sig.css|10:00, 23 March 2009 (UTC)}}


 * Erf, i hate edit conflicts. I was posting this :
 * I dont know if it's related but i read somewhere that when using any kind of "if", both "true" and "false" parameters will be evaluated and parsed before it check wich one to keep. — TulipVorlax 10:03, 23 March 2009 (UTC)

What if I split the code into different templates. For example: {{#ifexist:{{{1|}}} }}
 * {{ subst:internal link}}
 * {{{2|{{{1}}}}}}

Content of {{tl|internal link}}: {{{2|{{{1}}}}}}

Of course it's wrong and doesn't work. But that's the idea.--Comeon 15:39, 23 March 2009 (UTC)
 * Yes i understand, and it will not work as you intended for the same reasons i gave you, in my last edit this example you are subst the template internal link the ifexists will still exists regardless of the outcome since you are not subst it --{{User:Cizagna/Sig.css|21:50, 23 March 2009 (UTC)}}


 * It seems there is no workaround to do so. Thanks a lot for your answer. --Comeon 19:36, 25 March 2009 (UTC)