Evaluate format template content in (Semantic-)Mediawiki - mediawiki

I am using semantic mediawiki to store and describe information about scientific papers. In this context I would like to build a citation template that links to the page where the paper is described.
Every Paper has an identifier which is a combination of first author and year with the property like this: [[Has citekey:someauthor2019]]. I use a template to cite this paper as {{Cite | someauthor2019}} and combine the Cite template with a format template to render it as a link to the page with the name of the citekey.
The problem is that when I do it with the templates below, it will actually display the wikitext:
[[Name of the page | someauthor2019 ]]
instead of evaluating it to appear as the named link:
someauthor2019
This is the semantic-mediawiki ask query to get the paper information:
Template:Cite
{{#ask: [[Has citekey::{{{1}}}]]
|?Has citekey
|format=template
|template=Cite Text
}}
This is the format template to deal with the results of the query:
Template:Cite_Text
[[{{{1}}} | {{{2}}}]]
How can I get the avaluated result of a named link to be displayed instead of the wikitext?
Thank you in advance for any help!

Try to use
|link=none
this will pass {{{1}}} result as raw text to your template
You request becomes :
{{#ask: [[Has citekey::{{{1}}}]]
|?Has citekey
|format=template
|template=Cite Text
|link=none
}}
Source :
https://www.semantic-mediawiki.org/wiki/Help:Inline_queries#Standard_parameters_for_inline_queries

Related

Semantic Media Wiki Categories for Templates

We are running MediaWiki 1.34.2 with SMW 3.2.0 and want to query (ask) for all templates of a certain Category. The category is shown on the template page and the template is shown on the category page. But when using Special Page Browse wiki, the category is not shown. When printing the response of the query, the list is not complete and no template has a category. We added the required namespaces and tried to rebuild the wiki.
Template:
<noinclude>
[[Category:Test]]
<pre>
{{Device
|Name=
}}
</pre>
</noinclude>
<includeonly>
{| class="wikitable"
! Name
| {{{Name|}}}
|}
[[Category:TestInt]]
</includeonly>
Ask:
{{#ask:
[[Template:+]] | ?Category
}}
To ask for templates in a certain category, you need to ask for the category like
{{#ask:
[[Template:+]][[Category:Some Category Name]]
}}
See also https://www.semantic-mediawiki.org/wiki/Help:Inline_queries

Pulling API data into Django Template that has <a></a> tags embedded, is there a way of wrapping the text in an HTML tag?

I'm reading a very large API, one of the fields I need, have "a" tags embedded in the item in the dictionary and when I pull it into my template and display it, it shows the "a" tags as text.
exp:
"Bitcoin uses the SHA-256 hashing... ...such as Litecoin, Peercoin, Primecoin*"
I would like to wrap this in HTML so when it displays on the page it has the actual links rather than the 'a' tags and the URL.
What I'm looking to get:
"Bitcoin uses the SHA-256 hashing... ...such as Litecoin, Peercoin, Primecoin*"
I figured it out, I used the Humanize function with the |safe tag.
Pretty simple answer.
In the settings.py add 'django.contrib.humanize' to the INSTALLED_APPS:
**INSTALLED_APPS = [
'django.contrib.humanize', ]**
In the HTML Template add
{% load humanize %}
For the data you want to format use |safe
{{ location.of.data|safe }}
This will read the text as HTML.

Mediawiki: how can I use {{PAGENAME}} as part of the file name in a gallery?

I have 3 images that start with the PAGENAME and have different endings. Now I want to display them in a gallery like this:
<gallery>
File:{{PAGENAME}}.png|Adult
File:{{PAGENAME}} Egg.png|Egg
File:{{PAGENAME}} Baby.png|Baby
</gallery>
But the PAGENAME doesn't transclude and the gallery stays empty.
How can I achieve that?
Thanks
edit: I would also like to add the mode="slideshow" parameter to it
Html tags have priority in page content parsing, which means that any parser function inside is interpreted as string. So you need to turn them into a parser function, using #tag
{{#tag:gallery | content }}
Note that you cannot have literal pipes inside content, you have to turn them into a template call, using build-in pipe template:
{{!}}
You'll end up with this code:
{{#tag:gallery |
File:{{PAGENAME}}.png{{!}}Adult
File:{{PAGENAME}} Egg.png{{!}}Egg
File:{{PAGENAME}} Baby.png{{!}}Baby
|mode=slideshow}}

reusing handlebars & panini partials with different data

I've a number of 'building blocks' I've created of my own to use when templating a site and I'm wondering how I could use Panini to re-use partials on the same page, with different data.
Say for example I have a partial which basically adds a h1 tag followed by a single p tag but I want to be able to re-use that same partial on the same page with different data each time.
This is the content of the partial file for example;
<h1> {{ h1Header }}</h1>
<p> {{ pParagraph }} </p>
The Frontmatter data in the Index file;
---
h1Header: Hello!
pParagraph: This is some text.
---
And this to call the partial into action;
{{> partial }}
Unless I'm doing something fundamentally wrong the way I'm using it at the moment would mean I'd have to create several different partials for each possible outcome.
I was wondering if there was some way of sending arguments etc. If someone can point me in the right direction with even the simplest of examples just to get a feel of what I can do and what to look into I'd be grateful.
You can pass data to your partials passing a context or parameters to your partial. You can pass different data every-time you render the partial, according to the manual.
Having a partial called test:
<h1>{{foo}}</h1>
You can render it with specific data:
{{> test foo="bar"}}
{{> test foo="foobar"}}
Which results in
<h1>foo</h1>
<h1>foobar</h1>

Semantic Mediawiki #ask query with long result

I use Semantic Mediawiki and Semantic Forms.
I made a form that uses subobjects. So for showing on Mediawiki page the text that user has written in my form - I use #ask query and wiki template. My ask code is like this:
{{#ask: [[-Has subobject::{{FULLPAGENAME}}]]
|?MyProperty1
|?MyProperty2
|format=template
|template=MyTemplateLayout
|introtemplate=MyTemplateLayoutHeader
|outrotemplate=MyTemplateLayoutFooter
|named args=yes
}}
It works when user's text in the form is small. But if text has enters, bullets or <br> tag inside it - query result is empty:
Is it possible to configure or hide the long text in my forms to make working query result? How can I do it?
Just in case - my template code is:
{{#if:{{{?MyProperty1|}}} {{{?MyProperty2|}}}|
{{!}}- style="background-color: WhiteSmoke;"
{{!}}{{{?MyProperty1|}}}{{!}}{{!}}{{{?MyProperty2|}}}
{{!}}-
}}
And my Form code is like:
{{{for template|MySubobject|multiple|add button text=Добавить|embed in field=Test[TestField]}}}
{{{field|MyProperty1|input type=textarea|cols=90|rows=1|autogrow=true}}}||{{{field|MyProperty2|input type=textarea|cols=90|rows=1|autogrow=true}}}
...
Please ensure that your property has type Text ( create page Property:MyProperty with contents [[has type::Text]] ).