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)


 * There are partial workarounds the thing is there is no automatic system to do so, they're semi-manual but more like manual to be correct and to be more easy to work you need a user that has a bot and do repetitive tasks every now and then making this template tedious to maintain just to avoid "red links" --{{User:Cizagna/Sig.css|03:05, 26 March 2009 (UTC)}}

OK. I have a new idea. What if we create a bot to check every now and then? This is the idea: Is it possible? What's the script for that bot? (I have shallow knowledge only) --Comeon 22:30, 26 March 2009 (UTC)
 * 1) Tell the bot to search for {{tl|zhwiki}} (this is the template to link to wikipedia's, i.e.   )
 * 2) Check to see if we have the internal links now for that entry.
 * 3) If so, replace {{tl|zhwiki}} with   (internal links). Otherwise leave it intact.

if you are going to use a bot to work this out, now an then this is what you will have to do:

Create Template:A(you can change for another names) with the following code: {{ subst: #ifexist:{{{1|}}}|{{{2|{{{1}}}}}}|{{Zhwiki|{{{1}}}|{{{2}}}}} }}

Then go and create Template:Zhwiki (i use the same name as you gave also if you change name you have to adjusto it inside Template:A) put the following code: {{{2|{{{1}}}}}}

Instructions that you have to program with the bot:
 * 1) Look all the pages that link to Template:Zhwiki
 * 2) Replace  for

Now what its doings so you add a link  this will do as explained on my other edits, but here goes again, will substitute template:A then at the same time it will check if the page Chi exists if it exists it will leave a link   if it does not exists it will leave a template call like this   that it will be displaying the link. Now the bot will have to search from time to time all pages that are linking/transcluding from Template:Zhwiki and will have to replace the simple template call to Template:Zhwiki for a substitution of Template:A   that will again recheck if the page exists and if it exists... etc keeping the cycle.

And as i said this is a heavy to maintain process since the wiki becomes dependant of your bot in order to keep working (unless a user steps out to A.-manually do it or B.-program his own bot). Also if template A is not substitute it will not work

There are various bots programs some use scrips some dont so its more like what you can find and if you can manage to make work --{{User:Cizagna/Sig.css|08:45, 27 March 2009 (UTC)}}