On my wiki I am trying to create a conditional table template.
Here is the template code:
{| class="wikitable"
{{#if:{{{bazikade1|}}}{{{bazikade2|}}}|
{{!}}-
! بازیکده
{{!}} {{{bazikade1}}}
{{!}} {{{bazikade2}}}
}}{{#if:{{{bazinovin1|}}}{{{bazinovin2|}}}|
{{!}}-
! بازی نوین
{{!}} {{{bazinovin1}}}
{{!}} {{{bazinovin2}}}
}}{{#if:{{{boardboard1|}}}{{{boardboard2|}}}|
{{!}}-
! بردبرد
{{!}} {{{boardboard1}}}
{{!}} {{{boardboard2}}}
}}{{#if:{{{boardgamecenter1|}}}{{{boardgamecenter2|}}}|
{{!}}-
! بوردگیم سنتر
{{!}} {{{boardgamecenter1}}}
{{!}} {{{boardgamecenter2}}}
}}{{#if:{{{boardgameclub1|}}}{{{boardgameclub2|}}}|
{{!}}-
! بوردگیم کلاب
{{!}} {{{boardgameclub1}}}
{{!}} {{{boardgameclub2}}}
}}{{#if:{{{doozshop1|}}}{{{doozshop2|}}}|
{{!}}-
! دوزشاپ
{{!}} {{{doozshop1}}}
{{!}} {{{doozshop2}}}
}}{{#if:{{{baziplanet1|}}}{{{baziplanet2|}}}|
{{!}}-
! سیاره بازی
{{!}} {{{baziplanet1}}}
{{!}} {{{baziplanet2}}}
}}{{#if:{{{synapsi1|}}}{{{synapsi2|}}}|
{{!}}-
! سیناپسی
{{!}} {{{synapsi1}}}
{{!}} {{{synapsi2}}}
}}{{#if:{{{fekrofun1|}}}{{{fekrofun2|}}}|
{{!}}-
! فکروفان
{{!}} {{{fekrofun1}}}
{{!}} {{{fekrofun2}}}
}}{{#if:{{{goldendice1|}}}{{{goldendice2|}}}|
{{!}}-
! گلدن دایس
{{!}} {{{goldendice1}}}
{{!}} {{{goldendice2}}}
}}{{#if:{{{gamestore1|}}}{{{gamestore2|}}}|
{{!}}-
! گیم استور
{{!}} {{{gamestore1}}}
{{!}} {{{gamestore2}}}
}}{{#if:{{{vestagame1|}}}{{{vestagame2|}}}|
{{!}}-
! وستاگیم
{{!}} {{{vestagame1}}}
{{!}} {{{vestagame2}}}
}}{{#if:{{{madamak1|}}}{{{madamak2|}}}|
{{!}}-
! مادمک
{{!}} {{{madamak1}}}
{{!}} {{{madamak2}}}
}}
|}
If I use both rows it looks good. As here:
But if I use one of them, it looks weired, as here:
How can I fix it? Isn't it because of unicode characters I am using within the code? I tried to debug it by shortening the code but no success yet.
Your template seems broken in a different way from your examples. The whole table will be displayed in one row because {{!}}- is not really on a new string and will not be recognised by the parser as new row command. This happens because all parser function (including {{if:}}) parametres are trimmed.
If you add <nowiki /> at the end of every line containing {{if:, you will correct this.
After doing this, in my wiki (left-to-right) the template worked as expected.
Related
I have a table with a feature to select value of a row to send it to the Flask backend, that on button click also redirects my users to a different endpoint. What I need is to open the new endpoint requested in a new webpage instead of the same page. My HTML code where the button is located is as follows. It envelopes a table column value.
{% for item in rows %}
<tr>
<td>{{ item[0] }}</td>
<td>
**<button** formaction="/stockpopup"
type="submit" name = 'stock' value = {{`item[11] }}>
{{ item[11] }}**</button>**
</td>
<td>{{ item[1] }}</td>
</tr>
{% endfor %}
</tbody>
</table>
I am looking for possible alternates to using JavaScript to achieve this outcome if anyone can help.
You can use the onclick method inside of html.
Something like this should work:
<button onclick="window.open('https://stackoverflow.com','_blank')">Open in new tab</button>
I have an infobox in a template, where I'd like to add a table.
I added it, but could not obtain a good result.
An example of infobox is:
But I want the table in "composition" section to be as large as the rest of infobox.
Here the source code (I cut for the interesting parts):
{| style="float:right;border:1px solid gold"
! colspan="2" style="background:gold;width:200px;font-size:10pt" | {{#external_value:common_name}}
|-
| colspan="2" style="text-align:center;font-size:10pt" | [http://m.muninn.land/coins/{{#external_value:obverse_image}}]<br />
|-
| colspan="2" style="background:gold;text-align:center;font-size:9pt" | Description
|-
| style="font-size:9pt" | Currency: || style="font-size:9pt" | {{#external_value:currency_name}}
|-
Cut 8<
| style="font-size:9pt" | Form factor: || style="font-size:9pt" | {{#external_value:form_factor}}
|-
| colspan="2" style="background:gold;text-align:center;font-size:9pt" | Composition
|-
| colspan="2" style="font-size:9pt;text-align:left" | {{coin composition|id={{{id|2}}}}}
|}
Where the table in template "coin composition" is:
{| class="wikitable"
! Material:
! Percentage: {{#for_external_table:<nowiki/>
{{!}}-
{{!}} {{{composition}}}
{{!}} {{{percentage}}}
}}
|}
I tried to adjust column width:
https://www.mediawiki.org/wiki/Help:Tables#Column_width
but not with good results...
How can I enlarge the table in the infobox?
For example, a page of the site, in beta, is online at http://en.muninn.land/index.php/1000_lire_Capital_Rome_1970
for full source code.
Add style="width: 100%" to the table.
{| class="wikitable" style="width: 100%"
! Material:
! Percentage: {{#for_external_table:<nowiki/>
{{!}}-
{{!}} {{{composition}}}
{{!}} {{{percentage}}}
}}
|}
But a better solution would be to integrate composition into the main infobox (the template Coin details).
Rewrite the Coin composition template thus:
|-
| style="font-size:9pt" | Material: || style="font-size:9pt" | Percentage:
{{#get_db_data:
db=munin
|from=geo.v_coin_composition
|where=comp_coin_id={{{id|1}}}
|data=comp_coin_id=comp_coin_id,composition=composition,percentage=percentage
}}
{{#for_external_table:<nowiki/>
{{!}}-
{{!}} style="font-size:9pt" {{!}} {{{composition}}}
{{!}} style="font-size:9pt" {{!}} {{{percentage}}}
}}
|}
Invoke it from a new line and remove the preceding
|-
| colspan="2" style="font-size:9pt;text-align:left" |
Or simply replace its invocation with its new source code.
I have a simple Flask application with just one table.
So python code is irrelavantly simple:
#app.route('/')
def home():
items = long_db_request()
return render_template("index.html", items=items)
#app.route('/extended')
def extended():
return render_template("animals.html")
And items is a huge JSON object.
I created a table which reflects that data:
<table>
<tr>
<th style="text-align:center">id</th>
<th style="text-align:center">creation time</th>
<th style="text-align:center">name</th>
<th style="text-align:center">animals</th>
<th style="text-align:center">number</th>
</tr>
{% for item in items %}
<tr>
<td> {{ item.id }} </td>
<td> {{ item.time }} </td>
<td>
{{ item.name }}
</td>
<td> {{item.group}} </td>
<td>{{ item.group|length }}</td>
</tr>
{% endfor %}
</table>
The table looks like:
As you can see, column animal contains a lof of object which makes it all difficult to percieve.
I want it to be like this
which is a lot easier to get. And show animals is a link to another page, where a pure json exists.
How can I achieve this?
I followed the doc of jinja2 and Flask and found method url_for() but in that case I have to pass all my json in query which is unacceptable..
How can I jump from first image to exellent nice view of the second one?
working code with the first picture is place here
Thank you very much in advance!
P.S. I only saw one question here with rellevant topic, but it does not help me
Instead of passing all the animals (e.g. cats) from one view to another, just pass the category cats to the next page.
The view function for the next page then selects all cats from the json, and passes the cats then to the detailed view.
So, on you overview page, you render links like species.html?cats (and so on), and when somebody clicks on these links the view function selects all cats, and then passes them into a render_template("species.html", species=cats) view.
I'm using jinja2 and python.
Everything works but a table printed based on a string of arrays, this is the template
<table>
<tr>
<th> {{table.title}}</th>
</tr>
<tr>
{% for value in table.values %}
<td> {{ value }} </td>
{% endfor %}
</tr>
</table>
Table is defined in data in the pyton:
data['table'] = {
'title': 'Title',
'values': ['test','test2']
}
templateVars = data.copy()
templateEnv = jinja2.Environment(
loader=jinja2.FileSystemLoader(f'{package_directory}/assets/templates/'))
outputText = template.render(templateVars)
When executing I get an error:
{% for value in table.values %}
TypeError: 'builtin_function_or_method' object is not iterable
I can't find the error, because I created a list, and it should be iterable. I copied the same code to python and it works.
I solved my problem, it was I was using "values" as key and it's a reserved word, changing it for table_rows it works
I am working on a Jekyll website which needs an agenda. I would like to add points to the agenda in my _config.yml file so it looks like this in the file.
agenda:
date: 26 January
thing: Birthday
date: 30 March
thing: Another birthday
Another option would be:
agenda:
item: <td> Date </td> <td> Thing </td>
item: <td> Date </td> <td> Thing </td>
As you can see above the output has to be a list. It does not work no matter what I try. This is the last thing I have tried.
<table>
<tbody>
{% for point in site.agenda %}
<tr>
{{ point }}
</tr>
{% endfor %}
</tbody>
</table>
I hope you can help me solve this problem!
I can't try this right now, but what about:
agenda:
- date: January 26
event: Birthday
- date: May 30
event: Another birthday
Note: (make sure that the - is indented by at least one space and that indents match)
And then:
<table>
<tbody>
{% for point in site.agenda %}<tr>
<td>{{ point.date }}</td><td>{{ point.event }}</td>
</tr>{% endfor %}
</tbody>
</table>
Or something quite similar. In one page, I have an alternative syntax:
agenda:
- { date: January 26, event: Birthday }
etc...
That works like a treat.