I want to render multiple dicts json to front.
All in the same interface.
But each one in a specific tab.
And the tabs have to be created dynamically based on the number of dicts.
A basic example
[{"name" = a, "age" = 29},{"name" = b, "age" = 19}, {"name" = c, "age" = 28}]
The first tab will be a table containing the first dict {"name" = a, "age" = 29}, the second tab a table containing {"name" = b, "age" = 19} and so one.
Knowing that I don't now the length of json in advance
The question is not very clear but from what I understood, you can do something like this:
{% for tab in my_tab_list %}
<tab> Name: {tab.name} Age: {tab.age} </tab>
{% endfor %}
Related
I have a large dataset with coded column names. I made a dictionary with corresponding labels that explain the field, as such
codes = {
"Q1r1" : "first",
"Q1r2" : "second",
"Q1r3" : "third",
"Q1r4" : "etc...",
}
So now I would like to replace field names in tooltip with respective labels from codes.get(), but cannot figure out how to refer to outside dict from either .encode() or any .transforms.
Just to be clear: if the field referenced in below code is "Q1r1", I would like to have it shown in tooltip as "first" instead.
alt.Chart(df).mark_point().encode(
x='x:Q',
y='y:Q',
size='z:Q',
color=alt.Color('group:N'),
tooltip=['group:N', 'field:N']
)
How about mapping the group names first:
df['group_mapped'] = df['group'].map(codes)
alt.Chart(df).mark_point().encode(
x='x:Q',
y='y:Q',
size='z:Q',
color=alt.Color('group:N'),
tooltip=['group_mapped:N', 'field:N']
)
i need a help for make the result.
my sql request :
$posts = $db->prepare('SELECT
CM.idpost,
CM.title,
CM.slug,
CM.content,
CM.cover,
CM.date,
GROUP_CONCAT(PC.id SEPARATOR ";") AS list_id,
GROUP_CONCAT(PC.cat_name SEPARATOR ";") AS list_cat_name,
GROUP_CONCAT(PC.icon SEPARATOR ";") AS list_icon,
GROUP_CONCAT(PC.bg SEPARATOR ";") AS list_bg,
GROUP_CONCAT(PC.slug_cat SEPARATOR ";") AS list_slug_cat,
U.iduser,
U.username,
U.avatar
FROM cms_posts CM
LEFT JOIN relation_posts RP ON RP.id_post = CM.idpost
LEFT JOIN cms_postcategory PC ON PC.id = RP.id_category
LEFT JOIN users U ON U.iduser = CM.author
GROUP BY CM.idpost
ORDER BY CM.date DESC LIMIT '.$paginationStart.','.$limit.'');
this is what my sql query for my table returns: Marketing;Général in Twig :
{{ post.list_cat_name }}
Picture demo
I need the result :
Marketing
Général
Thanks for help <3
So you've got a string like Marketing;Général. You need to create 2 links using the text for each as the link text.
I assume you similarly need to split the list_id for your idcategory value.
So something like this:
{% set categoryNames = post.list_cat_name | split(';') %}
{% set categoryIds = post.list_id | split(';') %}
{% for category in categoryNames %}
{{category}}
{% endfor %}
https://twig.symfony.com/doc/2.x/tags/for.html#the-loop-variable
https://twig.symfony.com/doc/2.x/filters/split.html
Basically, I have set a parameter called "rating" that's equal to a product.DETAILS.STAR_RATING which is a value imported from a database-driven field which happens to be a string, I want to multiply this value by 20 but since "rating" is a string I cannot multiply it.
How do I convert the string to a float value?
{% set rating = product.DETAILS.STAR_RATING %}
{{rating * 20}}
Very simple way, maybe strange but...
{% set rating = 0 + product.DETAILS.STAR_RATING %}
{{ rating * 20}}
In Bokeh when using HoverTool, we end up using the "absolute name"
hover = HoverTool()
hover.tooltips = [
('name of salesperson','#name'),
('No. of Sales','#sale_num'),
('Sales Revenue in USD','#sale_rev')
]
p.add_tools(hover)
when the dataframe has the columns names as "name", sale_num" and "sale_rev".
Is there a way to use variable names rather than actual column names?
So, if I set
var_01 = "name"
var_02 ="sale_num"
var_03 = "sale_rev"
How do I use something like:
('name of salesperson','#var_01')
rather than the corresponding
('name of salesperson','#name')
Sure:
var_01 = "name"
var_02 = "sale_num"
var_03 = "sale_rev"
Then:
('name of salesperson','#' + var_01)
That will substitute things on the Python side of things, it will immediately generate:
('name of salesperson','#name')
because that's what's how standard Python string concatenation works, and then this is what gets sent to the browser.
If you are asking if there is some way to have this indirection cross over to the browser side (i.e. such that if you change the variable, the displayed content will update) the answer is No, because the browser knows nothing at all about your Python code or variables.
I'm trying to create a multiline string variable in swig :
{% set myVariable = "
multi
line
string
" %}
Then I log it :
{% logMyVariable(myVariable) %}
But I don't understand why my variable is not displayed on several lines :
multi line string
Whereas I was expecting :
multi
line
string
Do you know how I could do that?
In HTML, new lines in text aren’t rendered when the text is displayed. For example, this HTML:
<p>Let’s split this sentence up
onto
multiple
lines.</p>
Will render like this:
Let’s split this sentence up onto multiple lines.
You might want to wrap your log in a <pre> tag, as that will preserve new lines (and multiple spaces between words, which are also ignored in rendered HTML):
<pre>{% logMyVariable(myVariable) %}</pre>