Community Central

Admin Forum:How to use nowiki in Templates?


Admin Forum:How to use nowiki in Templates?

19,805pages on
this wiki
Add New Page
Talk0 Share

This Forum has been archived

Forums: Admin Central Index Technical Help How to use nowiki in Templates?
Central's forums are a place for the community to help other members.
To contact staff directly or to report bugs, please use Special:Contact.
Note: This topic has been unedited for 418 days. It is considered archived - the discussion is over. Do not add to unless it really needs a response.

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:

<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;">{{{1}}}</div>

And I would use it like this:

{{Code|<nowiki>void main () { doStuff(); }<nowiki>}}

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:

{{Code|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 <div id="script">ECMAScript code</div> and add the following jQuery to MediaWiki:Common.js:
$('#script').prepend('<script type="application/javascript">').append('</script>');
{C}it should work. Cheers! TK999 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. TK999 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. TK999 21:42, February 10, 2012 (UTC)
Wouldn't I have to somehow rewrite the code?
Pecoes 21:51, February 10, 2012 (UTC)

(Reset indent) {{Code|void main () doStuff(); </nowiki> or whatever the name is should work fine. TK999 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. TK999 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)
You can use the <pre> tag, and change how it displays with CSS. Normally, <pre> displays like this:
function foo() {
You can change that by adding style rules to <pre> in MediaWiki:Wikia.css on your wiki. For example:
pre {
	border:1px solid #998b7a;
	font-family:"Courier New", Courier, monospace;
Which should be similar to what you have above.  Monchoman45  Talk  Contribs  Skystone  22:40,2/10/2012 
Nice! That works! Thank you! :)
Pecoes 22:58, February 10, 2012 (UTC)