Extension talk:Variables

Jump to navigation Jump to search

About this board

You can use this board to submit questions and requests concerning the Variables extension. If you want to participate in development, please pick a task on Phabricator or create a new one,

Archive

Calling #var on a different template?

2
119.92.13.245 (talkcontribs)

I'm pretty new to this so it's still confusing to me.

So I have template1 and template 2. Template 1 does usd=12345, template 2 on the other hand has prize=5000. Is it possible to do match between these two tho they're on two different templates? I was trying the following but can't make it work and I'm stuck.

{{#vardefine:{{{result}}}|{{#expr:{{#var:prize}}*{{#var:usd}}}}}}

Dinoguy1000 (talkcontribs)

If the current template designs allow for it, I would recommend explicitly passing the needed values as template parameters, instead of relying on Variables. Not only does this bypass the problems you're facing now, but it also avoids a whole host of maintenance and code comprehension issues into the future.

Reply to "Calling #var on a different template?"

Is there a limit to the quantity of variables you have on one page?

2
Diriector Doc (talkcontribs)

I've never encountered a problem before when using many variables, but a thought came to me; How many variables can I have at once on a single page?

As an example, if I were to use, say, 100 variables one page for whatever reason, would I be able to do that without encountering a problem?

Asking out of curiosity.

Dinoguy1000 (talkcontribs)
Reply to "Is there a limit to the quantity of variables you have on one page?"

How to embed curly braces and quote-marks in variable?

7
Johnywhy (talkcontribs)

This is breaking my template. How to fix? I want the bolded part to be rendered verbatim with #var, but some characters (probably the curly braces) are getting interpreted as active wikitext characters, instead of just loaded into the variable.

{{#vardefineecho:HtmlLink|<htmltag tagname="a" href="/index.php/Portal:Tag?Tag={{{1}}}">}}

elsewhere:

{{#var:HtmlLink}}
Dinoguy1000 (talkcontribs)

The first thing I would try is surrounding the value with a <nowiki></nowiki> tag.

Johnywhy (talkcontribs)

Seems better, but still not rendering as expected.

the following:

{{#vardefineecho:HtmlLink|nowiki <htmltag tagname="a" href="/index.php/Portal:Tag?Tag={{{1}}}"> /nowiki}}

(note, the nowiki tags above ARE surrounded with < and >, but if i include them here then you cannot see the nowiki tags here)

renders, on the template page, as:

<htmltag tagname="a" href="/index.php/Portal:Tag?Tag={{{1}}}">

which is the desired wikitext.

Next, that output should then get parsed as normal wikitext in the template, where #var appears.

But, output of #var is not getting parsed as wikitext in the template, it's just getting rendered on the host-page verbatim, as if it's not wikitext.

It seems the nowiki tag in the #vardefine prevents the output of #var from getting parsed as wikitext.

Any ideas?

Dinoguy1000 (talkcontribs)

I don't think I understand what you're trying to do. What is the problem you're trying to solve here?

Johnywhy (talkcontribs)

i'm re-using a chunk of complex wikitext repeatedly in a Template. So i want to apply that wikitext to a variable for easy re-use, and easy revising.

Up to now, i tried to store the raw wikitext in the variable. But then, as reported above, the wikitext does not get parsed when retrieved with #var.

Next, i'm going to try parsing the wikitext before i store it in the variable-- if i can figure out how. Tips welcomed.

Dinoguy1000 (talkcontribs)

Is there a reason you don't use a subtemplate or metatemplate instead? It sounds like you're trying to use variables as a function of sorts, and that doesn't work; the content of a variable is parsed before it's stored in the variable.

Johnywhy (talkcontribs)

As explain in the OP above, it seems the variable can't be parsed correctly, because curlies in the value confuse your extension. That's why had to wrap it in nowiki.

Thx for telling me about subtemplate and metatemplate, i'll have to learn about that! But i get the general idea that i can use a template for re-used wikitext. Great idea.

Reply to "How to embed curly braces and quote-marks in variable?"

How to transclude invisible text?

1
Johnywhy (talkcontribs)

If template contains:

<nowiki><!-- this is a comment --></nowiki>

then the whole thing gets rendered as visible text on the host page.

If template contains:

<!-- this is a comment -->

then none of it gets transcluded.

Really just want to put some invisible text on the host page-- doesn't have to be an HTML-comment.

This doesn't get transcluded either:

<span style="display:none">Hidden Span</span>
Reply to "How to transclude invisible text?"

Distribution missing "extension.json"

2
أحمد (talkcontribs)
Kghbln (talkcontribs)

The docu states: "To users running MediaWiki 1.30 or earlier", so for MW 1.30 this extension has to be invoked via require_once ....

Reply to "Distribution missing "extension.json""

Can you query the contents of these variables for a given page id using the API?

4
174.97.28.4 (talkcontribs)
Danwe (talkcontribs)

That's not supported by the extension. You'd need to write a new extension on top of Variables to achieve this but it's not impossible.

MGChecker (talkcontribs)

It's an interesting thought to save the distinct var_final values in page_props to make it queryable… Maybe I will put some effort in implementing this additional functionality at some point in the future.

MGChecker (talkcontribs)
Reply to "Can you query the contents of these variables for a given page id using the API?"

{{#vardefineecho:n|{{#expr:{{#var:n}}+1}}}}

6
Cavila (talkcontribs)

I recently advised someone to use this in a template but I was wrong: multiple instances of such a template will print a series of 1, 1, 1, 1, etc., while use of the same syntax without a template will give you a series of 1, 2, 3, 4, etc. Is this intended behaviour?

92.21.226.2 (talkcontribs)

If you repeatedly call a template without parameters, it will reuse the output of the first call. To make sure the template is evaluated each time you need to add an empty parameter: {{template|}}.

Cavila (talkcontribs)

Great, that should do it - thanks for this!

DavidBiesack (talkcontribs)

Ouch! This makes using variables and templates much more difficult. Is there some way to bypass the cache behavior so the template is expanded every time?

Danwe (talkcontribs)

When I last worked on the extension this didn't seem possible if I remember correctly. Or it was more effort than I thought was justified to solve this.

Just call the template with an empty parameter as pointed out above.

MGChecker (talkcontribs)

This is tracked in T191574 and hopefully fixed soon.

Reply to "{{#vardefineecho:n|{{#expr:{{#var:n}}+1}}}}"
Yukii (talkcontribs)

can someone say if this extension works with MW1.30.x?

Dinoguy1000 (talkcontribs)

It does, yes.

Reply to "Works with MW 1.30.X ?"

Is this extension enabled on this site as well as Wikipedia?

2
Summary by Danwe

No. And it most likely never will be.

Yhynerson1 (talkcontribs)
Wargo (talkcontribs)
Reply to "Is this extension enabled on this site as well as Wikipedia?"

value starting/finished with spaces

2
145.236.252.35 (talkcontribs)

I'd like to use text values on my page like this:

" any text with preceding spaces"

how can i define it?

Protnet (talkcontribs)
{{#vardefine:text|&nbsp;any text with preceding spaces}}
Reply to "value starting/finished with spaces"