Is there a way to set a "new" parameter, internally to a template or other page? - mediawiki

Let's say I have some page which can take two parameters, x and y. I often find myself doing things in that page like in this silly little example:
{{#if: {{{x|{{{y|}}}}}} | '''{{{x|{{{y|}}}}}}'''. I repeat, {{{x|{{{y|}}}}}}.}}
In many cases, I would greatly prefer to simplify the reuse of {{{x|{{{y|}}}}}}, for clarity, for ease of typing, and for making it more difficult to miss or to screw up. So, I'd like to do something like the following hypothetical syntax:
{{#set:z|{{{x|{{{y|}}}}}}}}
{{#if: {{{z|}}} | '''{{{z}}}'''. I repeat, {{{z}}}.}}
That is, make a new parameter, z, which was not passed to the page, but nonetheless can be used in the page. Is there a way to do something like this?

There is the extension Variables, but it assumes a certain order of parsing, which will not be the case when pages are parsed with Parsoid.
To guarantee the right order of parsing you can use Lua.
But the simplest way will be to create a new template, taking only one parameter and to call it from the original one.
Template1:
{{template2| z = {{{x|{{{y|}}}}}} }}
Template2:
{{#if: {{{z}}} | '''{{{z}}}'''. I repeat, {{{z}}}.}}

Related

Pine Script - Dynamic Variables? (not necessarily correct terminology)

//#version=5
tspy = 60
blue = color.new(color.blue,tspy)
now when this following code executes many lines below/later:
tspy := 0
plot(rsi, title='bullish', color=blue)
As would be expected this does not change the transparency of variable blue by itself, obviously I can put blue := color.new(color.blue,0), but that is not ideal.
Is there a type of variable that is dynamic and will update itself whenever a variable contained within it changes, rather than having to manually re-execute the variables expression?
I have also tried setting the colours into a "function" call, but this seems to get complicated and causes more problems and code than just reentering/duplicating the original code. This may seem trivial, but it has a much wider importance and use case in more complex coding than this particular example.
Why not use a function?
//#version=5
indicator("My Script")
get_color(transp) => color.new(color.blue, transp)
plot(series=1, color=get_color(100))
plot(series=2, color=get_color(80))
plot(series=3, color=get_color(60))
plot(series=4, color=get_color(40))
plot(series=5, color=get_color(20))

Semantic mediawiki #ask query: Displaying nested properties on the same query

I would like to display in the same query properties of a page which is related to the pages im querying for.
Let's say I would like to query all the pages in the City category, which are located in Germany, and I want to display the title of the page, but also I want to display the surface data of Germany, for example.
Something like this: {{#ask: [[Category:City]] [[location::Germany]] |?mainlabel |?Location.surface }}
I know this wont work, but you can see what I want to achieve.
I'm not sure if there's a way to nest queries directly inside other queries. The normal method of doing it is using a template. So you might define a template (or subpage of the template if this going into a template) called {{tablerow}} that consists of:
<includeonly>
|- valign="top"
| [[{{{1|}}}]]
| {{#show: {{{1|}}} | ?surface }}</includeonly>
The <includeonly> tags are important for reasons I don't really understand, it produces errors sometimes if you leave them out. Then you just run an #ask query with format = template. (You can build the header into the query, but I find it simpler to just put it outside.)
{| class="wikitable smwtable sortable"
|- valign="bottom"
! [[City]]
! [[Surface]]
{{#ask: [[Category:City]] [[location::Germany]]
| format = template
| template = tablerow
| link = none
}}
|}
That will punch each result returned by the query through the template as {{{1}}} and generate a row based on it. If you have other data to return from the main query, additional properties that you ask for will come out as consecutive unnamed parameters (so if you include | ?population, that will go into the template as {{{2}}} and will need to be added to the row structure or it will be dropped).

How do I (easily) dynamically name helper elements in Razor?

I'm just starting out in Razor, and my first inclination was to treat Helpers like .ACSX's.
Let's say I make a very simple helper:
#helper HowManySpans() {
<div>
<input type="text" name="txtLoops" /><input type="submit" value="how many?" />
#{ if (IsPost) {
var count = Request["txtLoops"];
var i = 1;
while (i < count) {
<span>Span ##i</span>
i++;
}
}
</div>
}
It works fine until I place two on the same page. I was expecting the compiler to emit the name of the elements prefixed like ASPX pages generally do, yknow, ctl00_Header_txtLoops or something like that.
I guess in a more argument-driven helper, I could use my arguments to prefix names myself, but I feel that still postpones the issue. If I had some dynamic helper that prefixed names with a certain argument, I could still only have one on a page with that argument.
Am I overlooking something painfully obvious?
Razor emits only the markup that is in the page. It has very little in the way of augmenting the markup. Razor v2 added conditional attributes, but that is still somewhat explicit on behalf of the developer.
One question I have is why do the elements even need unique names. In many modern HTML5 applications there is little need for elements to have unique names.
But, suppose, there is a need, there are two ways I can think of to do it:
Have the caller pass in a name or name prefix (as you suggested).
Create your own counter, and increment it every time the helper is called. The big question is where to save the counter's information. One logical place to save it would be the HttpContext.Items collection, which is a per-request "bag of data". Each time the helper is called it checks the Items bag to see what the current count is, increments it by 1, uses that number, and updates the bag.

Pass a template parameter to a semantic mediawiki query

In page "Massachusetts", I have defined an attribute:
[[country::USA]]
In page "Boston", I define another attribute, and reference a template:
[[state:Massachusetts]]
{{City
| state=Massachusetts
}}
In template: Template:City, I want to get the country of the city which uses the template by way of the state's property. I can reference the state like so:
{{{state}}}
And I can get the country by hand-coding the state:
{{#ask: [[Massachusetts]] | ?country=}}
But I want to do it using the parameter, like so:
{{#ask: [[{{{state}}}]] | ?country=}}
I'm told this should work, but however I format it, the command seems to return a list of all the attributes referenced in the wiki, whether I've defined them or not.
I see a lot of similar questions asked online, all described in various ways — nested queries, subqueries, linked properties, property chains, and so on — and they all have different suggested solutions, none of which seem to work. How can I do this, and is there a way to refer to this situation?
The syntax shown above works:
{{#ask: [[{{{state}}}]] | ?country=}}
So does:
{{#show: {{{state}}} | ?country=}}
Check your parameter declarations, make sure you aren't declaring any twice.

is line folded? - How to check for folds in VIM

I'm writing some folding functions and I am at a point where I need to check if the current line is actually a fold.
The reason for this is because it is a custom fold method that depends on searching/matching certain lines.
For example, if the current line is folded and looks like:
-FOO------------------------
If you do something like:
getline('.')
You would basically get FOO so there is no way (that I know of) to know if I am at a fold or not.
Is there a helper function for this?
I would think it would have to be something like:
is_folded('.')
I could probably mess with the foldtext to assign a special title for the fold but I want to avoid this.
From :help eval.txt
foldclosed({lnum})
The result is a Number. If the line {lnum} is in a closed
fold, the result is the number of the first line in that fold.
If the line {lnum} is not in a closed fold, -1 is returned.
You can check for a given line if it returns -1 or a line number, you can probably implement your isfolded() function this way.
If you are looking for Vim script function or feature , it is a good idea to start by searching in eval.txt which contains lots of relevant information.