Semantic MediaWiki: Use template results in #switch - switch-statement

I want to #switch cases within an #ask-template but it looks like #switch ignores the given result value of {{{2}}} and always displays the #default.
Is there a way to accomplish this? Am I missing something?
Thank you very much!
List:
{{#ask: [[Kategorie:Cat1]]
| ?Arg1
| ?Arg2
| ?Arg3
| ?Arg4
| format=template
| template=TableContent
| introtemplate=TableHeader
| outrotemplate=TableFooter
| sort=Name
| link=none
}}
Tablecontent:
<includeonly>
<tr>
<td>[[{{{1}}}]]</td>
<td>
{{#switch: {{{2}}}
| Case1 = [[File:icon1.png|24px|link=]] Case1
| Case2 = [[File:icon2.png|24px|link=]] Case2
| Case3 = [[File:icon3.png|24px|link=]] Case3
| #default = bla
}}
</td>
<td>{{{3}}}</td>
<td>{{#if:{{{4|}}}|{{{4}}}| }}</td>
</tr>
</includeonly>
Single page:
<!-- SMW code -->
<span style="display:none">
[[Kategorie:Cat1]]
[[Kategorie:Cat2]]
[[Arg1::{{PAGENAME}}]]
[[Arg2::Case2]]
[[Arg3::3x2]]
[[Arg4::foo]]
</span>

{{{1}}} is always the page title in SMWs template results format, therefor in your switch you need to use {{{3}}}, see https://www.semantic-mediawiki.org/wiki/Help:Template_format#Using_templates_for_custom_formatting

If you set named args=yes as a parameter of your ask query things might get simpler and clearer.
see:
https://www.semantic-mediawiki.org/wiki/Help:Named_args
Instead of {{{2}}} you'd use {{{?Args2}}} or {{{Args2}}} depending on your SMW Version (see link above).
Also you might want to provide a default e.g. use {{{Args2|}}}. There is also a Sandbox Wiki at https://sandbox.semantic-mediawiki.org/wiki/Main_Page in which you can tryout your approach so that people can follow your example better.

Related

How do I Correctly Render Python Data in Jinja HTML Templates?

I'm extremely new to python/flask, so I don't have the capacity to describe what I'm doing wrong. Please be patient with me.
As I'm in the learning stages, my goal is to create a simple app with GET, PUT, POST, DELETE functionalities. I'm using flask to render a template for a project; I'm using forms to make an HTML page. The one key issue here is:
in my routes.py
#app.route("/")
#app.route("/home")
def home():
all_pokemon = Pokémon.query.all()
result = ""
for pokemon in all_pokemon:
result += f"{pokemon.id} | {pokemon.pkname} | {pokemon.nickname}<br>"
return result
This, gives me what I want, which is this:
However, I have an home.html setup to do exactly the same thing. Simply show me this information.
in my home.html
{% extends 'layout.html' %}
{% block body %}
<h1>version 1.0.0</h1>
<br>
{% for pokemon in all_pokemon %}
{{ "{pokemon.id} | {pokemon.pkname} | {pokemon.nickname}" }}
<br>
{% endfor %}
{% endblock body %}
and to get that working, i have this in my routes.py
#app.route("/")
#app.route("/home")
def home():
all_pokemon = Pokémon.query.all()
return render_template("home.html", all_pokemon=all_pokemon)
But, doing this, gives me this output:
My question is, how do I get the render_template to NOT display the incorrect output, and to properly display the correct output of my forms?
I've been searching for an answer for this issue without an understanding of the proper terminology and have consequently made no progress for the past 3.5 hours. Any help is greatly appreciated. Swift help is incredibly appreciated.
Thank you. If I need to post more information please let me know.
I've figured it out, and as I suspected it was embarassingly simple.
The render template worked, but where I had
in my home.html
{{ "{pokemon.id} | {pokemon.pkname} | {pokemon.nickname}" }}
I should have had
{{ pokemon.id }} | {{ pokemon.pkname }} | {{ pokemon.nickname }}
I apologise for anybody who may have wasted their time searching for an answer, and I hope this can serve as a helpful guide to any other newbies like myself who get stuck on this.
Hopefully 7 years from now I can look back on this moment affectionately and laugh about it.
{% for pokemon in all_pokemon %}
{{ "{pokemon.id} | {pokemon.pkname} | {pokemon.nickname}" }}
<br>
{% endfor %}
Firstly you should use your context like that:
{{pokemon.id}} | {{pokemon.pkname}} | {{pokemon.nickname}}
And if you want to render your context, your view should be like that:
#app.route("/home")
def home():
all_pokemon = Pokémon.query.all()
result = ""
for pokemon in all_pokemon:
result += f"{pokemon.id} | {pokemon.pkname} | {pokemon.nickname}<br>"
if all_pokemon is not None:
return render_template("home.html", all_pokemon=all_pokemon, result=result)
else:
return render_template("home.html",all_pokemon=all_pokemon, result = "")
If you use your context named result, you should use a control in your template folder like that:
.html
{% if result|length > 1 %}
...
{% endif %}

Align top left and bottom right with material design

I might be getting this completely wrong, but trying to create a webpage where Div 1 is in top left corner, and div 2 is aligned bottom right (or end end). And I wanted to do this in the right way using material design.
I want it like this (sorry for the ASCII art, but it is cool)
_____________33____50________________
| | |
| 1 | |
| | _________________| 33
-------------| | |
| | 2 |
| | |
| | |
--------------------------------------
50
Here is the code so far, but the problem is I can get it to affect the alignment on column one, but I cant set them independently on the two divs
<md-content layout="column" layout-fill>
<div layout="column" flex="33"><H1>Welcome to My page</H1>
</div>
<div layout="row" layout-align="end end" flex="33">
<div layout="column" layout-align="end end" flex="50">
<H3>Welcome to my page</H3>
<p>This is my page, there are many like it <bold>But this page is mine</bold></p>
<ul>
<li>
My page is my best friend
</li><li>
I must master its code
</li><li>
like I must master my life
</li>
</ul>
</div>
</div>
</md-content>
Not certain the JS fiddle works at all, managed to get the first bit working, but cant get the end. Is this just because we don't know how big the screen is?
Here is a simple JS fiddle, and Material Design is working, and I can get the flex to work, but not the align
https://jsfiddle.net/p02Ls1dh/3/
OK, sorry, me being silly, material design still don't know the height, so the way to do it is to set height (you can use javascript and window) to set the height to say 900px (style="height: 900px;" below), once that is done it works.
<md-content layout="column" layout-fill style="height: 900px">
<div layout="column" flex="33"><H1>Welcome to My page</H1>
</div>
<div layout="row" layout-align="end end" flex="33">
<div layout="column" layout-align="end end" flex="50">
<H3>Welcome to my page</H3>
<p>This is my page, there are many like it <bold>But this page is mine</bold></p>
<ul>
<li>
My page is my best friend
</li><li>
I must master its code
</li><li>
like I must master my life
</li>
</ul>
</div>
</div>
</md-content>

Retrieve a value inside a field using a custom twig / Select a column by it's block name / Sonata

I'll try to be clear as possible, as my question may not be simple.
I have a Sonata GridPanel, modelled (simplified) like this:
~~~~~~~~~~~~~~~
Name | Type | Blob
~~~~~~~~~~~~~~~
Boby | Aaaa | Bbbb
John | Cccc | Xxxx
Let assume the column Blob is a custom column I made which you can click on.
It is controlled by a custom twig.
My custom twig is like this
{% extends stuff %}
{% block field%}
<div class="opener">
<img
src="{{ asset('bundles/bobby/images/map_magnify.png') }}"
width="30"
height="30"
style="cursor:pointer;"
onclick="createPopUp('{{ admin.id(object) }}');"
>
</div>
{% endblock %}
As you can see, I pass the {{ admin.id(object) }} as a parameters of the function, so the function in my JS file will be aware of the value returned by the parameters.
For example, according to my grid there and assuming the ID of my object is the column Name, if I click on Bbbb, the {{ admin.id(object) }} will return Boby as a value.
This is working.
Now, I want to do quite the same thing, but not returns the ID of a whole object, but a specific value of an object.
Still according to my example, if I click on Bbbb, I would like to retrieve the value contained in the column Type for this object. The value should be then Aaaa.
But I don't know how to do this.
I tried to pass this {{ block('field') }}, but it does not target a specific column. How can I select the block by it's name.
I'm not familiar enough with twig and I'm quite lost looking inside all the Sonata's twig files.
How could I do this ?
You'll have to know to that in my case, the value I want to retrieve is "controlled" by a Sonata's Twig, and not by my custom twig.
I think you can do this using object var from the template:
{% extends stuff %}
{% block field%}
<div class="opener">
<img
src="{{ asset('bundles/bobby/images/map_magnify.png') }}"
width="30"
height="30"
style="cursor:pointer;"
onclick="createPopUp('{{ object.type }}');"
>
</div>
{% endblock %}
Take a look at row templates from sonata admin documentation for more informations

Jade template how to add text after tag on the same level

I am try to get this to work in jade template:
html:
<li><i class="icon-comment"></i> 5</li>
jade:
li:i.icon-comment 5
ofcource 5 now is nested under i tag rather then li. Any way to do this?
In my templates I do it like this:
li
i.icon-comment
| 5
There is many ways like:
Like the one shared with david using |
li
i.icon-comment
| 5
Add it in single line:
li #[i.icon-comment] 5

How to add new line Character ( \n ) in message resource bundle in JSF1.2

In my sample JSF application am using rich:dataTable in page to display data.
I have 2 header to display value in rich:dataTable like following
--------------------------------
| UserDetails | EmpoyeeDetails |
--------------------------------
In message resource bundle file having key and value like
usrDet = UserDetails
empDet = EmpoyeeDetails
I need to display like User in one line and Details in next line of that particular header
----------------------
| User | Empoyee |
| Details | Details |
---------------------
How to add new line character in message bundle between words? I tried by adding Hexadecimal code, Numerical Code for \n like
, \u000A but its not
working for me! Any Idea?
JSF generates HTML. Newlines in HTML are not represented by the \n character, but by the <br> element.
In order to have the HTML client to interpret \n too, you need to throw in CSS white-space: pre or pre-wrap:
key = Lorem ipsum.\nDolor sit amet.
<h:outputText value="#{bundle.key}" style="white-space: pre-wrap" />
Alternatively, use <br> instead and have JSF unescape it. E.g.
key = Lorem ipsum.<br/>Dolor sit amet.
<h:outputText value="#{bundle.key}" escape="false" />
Try the steps outlined here: http://www.mkyong.com/java/how-to-insert-a-new-line-in-resource-bundle-messages-java/
Basically, you use the StringEscapeUtils.unescapeJava(String str) static method.

Resources