Admin Forum:How to use nowiki in Templates?

I'm not at all happy with the way Wikia renders code. So I tried to create myself a template to use instead of the code-tag. Here's what my Template:Code looks like so far:

&lt;div style="border: 1px solid #998b7a; padding: 10px; background-color: white; color: black; font-family: "Courier New", Courier, monospace; font-style: normal; font-weight: normal; font-size: 14px; line-height: 18px; text-decoration: none; white-space: pre;"&gt;&lt;/div&gt;

And I would use it like this:

&lt;nowiki&gt;void main { doStuff; }&lt;nowiki&gt;

As you can see, I'm using the template and the nowiki-tag. What I would like to do is abstract this tag away into the template, so that I would only have to write this:

void main { doStuff; }

but all my attempts to transform the template failed miserably. Does anybody else haven an idea how to do that? Is that even possible? Should I try something completely different?

Pecoes 12:48, February 10, 2012 (UTC)
 * You cannot insert ECMAScript directly into a page, no matter the context. However, if you create a template page with  and add the following jQuery to MediaWiki:Common.js:

{C}it should work. Cheers! 21:07, February 10, 2012 (UTC)


 * Thanks, but I wasn't trying to insert ECMAScript. This isn't about active code at all. I want the code to be inserted as text with the formatting that's in the style-attribute of the surrounding div.


 * My problem is that the code may contain the characters "{", "}" and "|" and so I need to use nowiki-tags. But where? It's easy to use them in the code that calls the template, but what's the point of using a template in the first place, if it doesn't work without additional wiki-markup? So I want the nowiki-tags to be integrated into the template, but I can't figure out how...


 * Does that make my problem clearer?


 * Pecoes 21:25, February 10, 2012 (UTC)
 * Ah. You could create a page named Template:! then, with the content being a vertical bar, |, and make a similar for the curly brackets. This should fix it. 21:34, February 10, 2012 (UTC)


 * Er. Now you lost me. How would that fix it?


 * Pecoes 21:39, February 10, 2012 (UTC)
 * This way, if you transclude these templates, they will render as a vertical bar, left curly bracket or whatever is in them without breaking the template. 21:42, February 10, 2012 (UTC)


 * Wouldn't I have to somehow rewrite the code?


 * Pecoes 21:51, February 10, 2012 (UTC)

{{ Code|void main  doStuff; or whatever the name is should work fine. 21:54, February 10, 2012 (UTC)


 * That would be a bit pointless. The idea is that I can copypaste sample code from my game mod into the wiki, surround it with {{ Code }} and show the code to the reader with some decent formatting. I don't want to rewrite the code first!


 * Besides: It's not just those three characters. Without the nowiki-tag Wikia inserts all sorts of p-tags and span-tags into the code that have no business being there.


 * Pecoes 22:06, February 10, 2012 (UTC)
 * That's typically done by the RTE, the WYSIWYG editor. You could switch to source mode to ensure that it remains clean. If you disable category module in Special:Preferences and widen the source mode edit box, it essentially rules out unwanted tags. 22:11, February 10, 2012 (UTC)


 * I tried that. This is what I wrote in the editor:
 * and this is how it was rendered:
 * Pecoes 22:28, February 10, 2012 (UTC)
 * Pecoes 22:28, February 10, 2012 (UTC)
 * Pecoes 22:28, February 10, 2012 (UTC)


 * You can use the  tag, and change how it displays with CSS. Normally,   displays like this:

 function foo { bar; }
 * You can change that by adding style rules to  in MediaWiki:Wikia.css on your wiki. For example:

 pre { border:1px solid #998b7a; padding:10px; background-color:white; color:black; font-family:"Courier New", Courier, monospace; font-style:normal; font-weight:normal; font-size:14px; line-height:18px; text-decoration:none; white-space:pre; }
 * Which should be similar to what you have above. {{User:Monchoman45/SigReal|22:40,2/10/2012}}


 * Nice! That works! Thank you! :)


 * Pecoes 22:58, February 10, 2012 (UTC)