Topic on Project:Support desk

[RESOLVED] template variables within html tags

7
LEGEND383 (talkcontribs)

I am trying to place a template variable inside of a html tag, but instead of the variable contents I get

{{{1}}}

(the variable isn't being substituted with it's value). I have tried placing the start and end tags within their own templates and escaping the pointy brackets but neither worked.

Is there a way to do this, and if so, what is it?

Using MediaWiki 1.22.0

Bawolff (talkcontribs)

You need to be more specific. Please tell us exactly what you are doing (including what your template code is).

In wikitext (for html tags allowed in wikitext), you should be able to add template parameters like normal.

Pkmatte (talkcontribs)

I'm having the same issue, here is an example I'd like to use on our pages (internal wiki so no need to worry about security or anything):

==Auto login to page==
<html>
	<form action="page-action.php" method="POST">
		<input type="hidden" name="name" value="{{{username}}}" />
		<input type="hidden" name="pass" value="{{{password}}}" />
		<button type="submit" value="submit">Log In</button>
	</form>
</html>

I have "wgRawHtml" set to true, so I'm assuming what happens is, the wiki interprets everything in the <html> tags as raw HTML that it shouldn't touch, but I'd still like it to interpret those two variable, is there any way to achieve that.

Ciencia Al Poder (talkcontribs)

If you're using raw HTML, MediaWiki won't interpret anything inside it. Since I guess the username and password are always the same, you may put them directly on the page instead of using template parameters.

Pkmatte (talkcontribs)

They would not be the same, but I was able to get around it using JavaScript using something like the following:

==Auto login to page==
<span id="username_label">Username</span>
<html>
        <form action="page-action.php" method="POST" onsubmit="document.getElementById('username_input').value = document.getElementById('username_label').innerHTML;">
                <input type="hidden" name="name" value="" id="username_input" />
                <input type="hidden" name="pass" value="{{{password}}}" />
                <button type="submit" value="submit">Log In</button>
        </form>
</html>

My pure JavaScript is a little rusty, so I'm sure there's a more efficient way to do it, but hopefully that helps anyone coming across this topic.

Bawolff (talkcontribs)

To be more specific, to use template parameters in raw html blocks, you have to use #tag. e.g:

{{#tag:html|
        <form action="page-action.php" method="POST">
                <input type="hidden" name="name" value="{{{username}}}" />
                <input type="hidden" name="pass" value="{{{password}}}" />
                <button type="submit" value="submit">Log In</button>
        </form>
}}

Then wikitext parameters should get substituted (Should being the key word, have not tested it).

Reply to "[RESOLVED] template variables within html tags"