Hand over parameters from a MediaWiki template to a included one - mediawiki

I'm using the MediaWiki extension DynamicPageList (third-party) which can be used as a template:
{{#dpl:
|category=foo
|notcategory=bar
}}
I try to use this template in one of my templates which uses more parameter e.g.:
{{myTemplate
|category=foo
|notcategory=bar
|mypara1=bla
|mypara2=lala
}}
myTemplate looks like this:
do something with mypara1
...
do something with mypara2
...
{{#dpl:
|category=foo
|notcategory=bar
}}
I know my parameters but #dpl: can use one or many parameters.
How can I separate my parameters from the #dpl: ones? And how can I just hand over the parameters which belongs to #dpl:?
Thanks,
Ray

Finally I came up with the following solution:
DPL has an additional template #dplreplace. I'm using this to parse my parameters.
Call the template:
{{myTemplate
| filter=category:foo;notcategory:bar
| mypara1=bla
| mypara2=lala
}}
In the template I replace the : by = and ; by {{!}}.
{{#dpl:
| {{#dplreplace: {{#dplreplace: {{{filter}}} | /:/ | = }} | /;/ | {{!}} }}
| ordermethod = sortkey
| suppresserrors = true
}}
NOTE: {{!}} is a template which is replaced by |.
Regards;
Ray

Maybe I'm misunderstanding your issue, but you can just pass the parameters on to DPL, just like you would to a template, or another parser function. You might want to add an empty default in most cases:
myTemplate:
do something with {{{mypara1}}}
do something with {{{mypara2}}}
{{#dpl:
|category = {{{category|}}} <!-- default to empty string -->
|notcategory = {{{notcategory|}}} <!-- default to empty string -->
}}
Call it like this:
{{myTemplate
|category=foo
|notcategory=bar
|mypara1=bla
|mypara2=lala
}}
Will work with missing parameters too:
{{myTemplate
|category=foo
|mypara1=bla
|mypara2=lala
}}

Related

Use 2 pipes in Angular- HTML

I use curreny pipe, but it add digits after dot.
How to remove them?
The result of {{ 1111111 | | currency:'ILS' }} is 1,111,111.00.
I want to remove the ".00"
I tried to use both pipes, curreny and number:
{{ 1111111 | number: '2.0' | currency:'ILS' }}
but it don't give any result.
Try this
{{ 1111111 | currency:'ILS': 'symbol':'1.0-0' }}
symbol will remove zero's.
Please read the documentation is really explained in details. https://angular.io/api/common/CurrencyPipe
Happy coding

jinja2 get whole context in single object within template

For example, I have template index.html and custom_jinja2_filter
<h1> My name is {{ name }} </h1>
<h2> I'm {{ year }} years old </h2>
<p> I'd like to pass template context to custom
filter like single object. Is it possible?
{{ ??? | custom_jinja2_filter }}
</p>
def custom_jinja2_filter(context):
name = context['name']
year = context['year']
You can pass the current context to a function marked as callable with #contextfunction:
from jinja2 import contextfunction
#contextfunction
def custom_jinja2_filter(context):
name = context.name
year = context.year
return '(c) {} {}'.format(year, name)

AngularJS correct syntax for variable in brace inside another brace

Hello I can't find the way for doing this correctly :
{{point.localized ? "{{ 'CHECKED' | translate }}" :"{{ 'I_AM_HERE' | translate }}" }}
point.localized is a boolean and if it's true I want to display the translation for checked and if it's not the translation for I_AM_HERE how can I do this ?
What about this:
{{(point.localized ? 'CHECKED' : 'I_AM_HERE') | translate }}
Try this:
{{point.localized ? ('CHECKED' | translate) : ('I_AM_HERE' | translate) }}
Or the long way around, which is still valid:
<div ng-if="point.localized">
<span>{{'CHECKED' | translate"}}</span>
</div>
<div ng-if="!point.localized">
<span>{{'I AM HERE' | translate"}}</span>
</div>

Mediawiki: Displaying a List does not work with infobox template

I created a new template and want to display a list inside my newly coded infobox. To get this working I was told to change the code like in this German tutorial.
This is how my template Infobox Music currently looks like:
|-
{{#if: {{{Sänger<includeonly>|</includeonly>}}} |
{{#ifeq: {{Str left|{{{Sänger}}} }} | *
|{{!}} style="vertical-align:top;" {{!}}
'''Sänger/in'''
{{!}}
{{{Sänger}}}
|{{!}} '''Sänger/in'''
{{!}} {{{Sänger}}}
}}
}}
In order to build a new list I edited the source code in a seperate Wiki entry like this:
{{Infobox_Music
|Sänger =
* Lady Gaga
* Michael Jackson
}}
Unfortunately, when using both of these settings my list gets displayed with the first item having an * at the beginning just as usual. Here is how it looks in HTML:
<tr>
<td> <b>Sänger/in</b>
</td>
<td> * Lady Gaga
<ul><li>Michael Jackson</li></ul>
</td></tr>
Did I miss something? What does the line {{#ifeq: {{Str left|{{{Sänger}}} }} mean?
UPDATE: Here is a snippet of my previous Infobox Music template:
{{Infobox Music
|-
{{#if: {{{Sänger|}}} | {{!}} '''Sänger/in''' {{!!}} {{{Sänger}}} }}
}}
{{Str left|{{{Sänger}}} }} is the first character of the Sänger parameter (see {{Str left}}). {{#ifeq: {{Str left|{{{Sänger}}} }} | * | ... is some kind of horrible hack to use a different layout when the parameter is a list; not trying to replicate that will help you preserve your sanity.
* will only be interpreted as a list when preceded by a newline. You can prevent stripping of the leading whitespace from the template parameter by doing something like
|Sänger = <!---->
* Lady Gaga
or you can make sure that in the template {{{Sänger}}} is preceded by a newline.

MediaWiki: Calling Template, ParserFunctions condition depending on External data values

I'm trying to display data from MySQL DB in a table in my MediaWiki page. The data are fetched using External data extension functions #get_db_data and #for_external_table, which works fine. However, I would like to do two more things:
use the fetched value as a template name: when value in DB is x, then insert Template:X (or {{X}})
use (another) fetched value in a condition using ParserFunctions extension. Specifically, a number is returned. If the number is less than 100, display it in brackets, otherwise display nothing.
Here is the code so far:
{{#get_db_data:
db=pravidla
|from=alch
|order by=nazev
|data=nazev=nazev,prima=prima,primaproc=prima_proc,sekunda=sekunda,sekundaproc=sekunda_proc,dominanta=dominanta
}}
{| class="wikitable sortable" style="border: solid 1px black"
|+ Tabulka přísad
|''Přísada''
|''Prima''
|''Sekunda''
|''Dominanta'' {{#for_external_table:<nowiki/>
{{!}}-
{{!}} {{{nazev}}}
{{!}} {{{prima}}} ({{{primaproc}}} %)
{{!}} {{{sekunda}}} ({{{sekundaproc}}} %)
{{!}} {{{dominanta}}} }}
|}
The values in prima, sekunda and dominanta variables should be replaced by a template with the same name. Neither {{{{{prima}}}}} nor {{Lcb}}{{Lcb}}{{{prima}}}{{Rcb}}{{Rcb}} (where Lcb={ and Rcb=}) do work.
The bracket with the value in the middle two cells should be displayed only in the value is less than 100 (percent), so something like {{#ifeq: {{{primaproc}}} | 100 | | ({{{primaproc}}} %) }} should be in order, but I've had no luck despite trying.
Thank you for reading this, and any insights are welcome.
I managed to resolve both issues by replacing the ExternalData extension function #for_external_table with #display_external_table. The latter passes the retrieved data as variables to a template; the same code works when placed in a separate Template:Table row page. So the solution looks like this:
Original page, displaying the table:
{{#get_db_data:
db=pravidla
|from=alch
|order by=nazev
|data=nazev=nazev,prima=prima,primaproc=prima_proc,sekunda=sekunda,sekundaproc=sekunda_proc,dominanta=dominanta
}}
{| class="wikitable sortable" style="border: solid 1px black"
|+ Tabulka přísad
|''Přísada''
|''Prima''
|''Sekunda''
|''Dominanta''
{{#display_external_table:
template=Table row
|data=nazev=nazev,prima=prima,primaproc=primaproc,sekunda=sekunda,sekundaproc=sekundaproc,dominanta=dominanta}}
|}
Newly created Template:Table row page:
{{!}}-
{{!}} {{{nazev}}}
{{!}} {{ {{{prima}}} }} {{#ifeq: {{{primaproc}}} | 100 | | ({{{primaproc}}} %) }}
{{!}} {{ {{{sekunda}}} }} {{#ifeq: {{{sekundaproc}}} | 100 | | ({{{sekundaproc}}} %) }}
{{!}} {{ {{{dominanta}}} }}
Both using the prima, sekunda and dominanta values to call a template with the same name and conditional diplay of percents in the brackets work like a charm now.