printing the text of the select element from composite instead of key - drupal

I am trying to iterate and print the text of the select element selected by the user. The key of the composite is item.
{% for item in data.item %}
<tr>
<td style="text-align: center;">{{ item.qty }} </td>
<td style="text-align: center;">{{ item.book }}</td>
</tr>
{% endfor %}
I know that item.book would only print the key. So how would I change it to print the text?

Related

Print the table based on the selected option of a radio element

I have a radio element with three options (Normal, Time Sensitive, and Hold For Pick-Up). Every time an user clicks an option, an unique table element for the option (for user to fill information) will pop up automatically. Finally, I would like to print all the submitted data to PDF attachment.
As I write the twig code for it, I am stuck in the part where I want to print the table that belongs to the selected option
{# choose_your_shipping_option: radio's key #}
{# Normal: option text #}
{% if webform_token('[webform_submission:values:choose_your_shipping_option]') == "Normal" %}
<table>
<tr>
<th>Shipping Address:</th>
<th>Acct #</th>
</tr>
<tr>
<td rowspan="3">[webform_submission:values:shipping_address]</td>
<td>[webform_submission:values:id_num]</td>
</tr>
<tr>
<th>Phone</th>
</tr>
<tr>
<td>
[webform_submission:values:phone]
</td>
</tr>
</table>
{% elseif webform_token('[webform_submission:values:choose_your_shipping_option]') == "Time Sensitive" %}
<table>
<tr>
<th>Delivery Date</th>
<td>[webform_submission:values:time_sensitive_01_delivery_date]</td>
<th>Must Have Street Address (No PO Box)</th>
</tr>
<tr>
<th colspan="2">Shipping Address:</th>
<th>Acct #</th>
</tr>
<tr>
<td colspan="2" rowspan="3" style="text-align: center;">[webform_submission:values:shipping_address_2]</td>
<td>[webform_submission:values:id_num]</td>
</tr>
<tr>
<th>Phone</th>
</tr>
<tr>
<td>
[webform_submission:values:phone_2]
</td>
</tr>
</table>
{% elseif webform_token('[webform_submission:values:choose_your_shipping_option]') == "Hold For Pick-Up" %}
<table>
<tr>
<th>Will be picked up by</th>
<th>Pick-up Date:</th>
</tr>
<tr>
<td>[webform_submission:values:pick_up_01_picked_up_by]</td>
<td>[webform_submission:values:pick_up_01_pick_up_date]</td>
</tr>
<tr>
<th>Pick-up Location</th>
<th>Pick-up Time</th>
</tr>
<tr>
<td>[webform_submission:values:location]</td>
<td>[webform_submission:values:time]</td>
</tr>
</table>
{% endif %}
It would ruin the pdf template when I use webform_token. Is there a correct way to print only the one that's filled by the user?

How group item in for TWIG

How I can grouping item in list, if I have different items with one ID?
I want if loop find two or more items with the same id combine them in to list ul > li.
For example:
{% extends 'base.html.twig' %}
{% block wrapper %}
<div class="panel panel-default">
<div class="panel-heading clearfix add">
Заявки
</div>
<table class="table">
<tr>
<th>ID</th>
<th>ID заявки</th>
<th>Склад</th>
<th>Матеріал</th>
<th>Кількість</th>
<th>Сумма</th>
<th>Дата</th>
<th>Час</th>
<th>Користувач</th>
</tr>
{% if itemEntries == null %}
<tr>
<td colspan="6">Елементи для показу відсутні</td>
</tr>
{% endif %}
{% for value in itemEntries %}
<tr>
<td>{{ value.id }}.</td>
<td>{{ value.bid }}</td>
<td>{{ value.storage.name }}</td>
<td>{{ value.item.name }} (ID: {{ value.item }})</td>
<td>{{ value.count }}</td>
<td>-{{ value.count * value.item.price }}</td>
<td>{{ value.date | date('d-m-Y') }}</td>
<td>{{ value.time | date('H:m:i') }}</td>
<td>{{ value.userLogin }}</td>
</tr>
{% endfor %}
</table>
</div>
{% endblock %}
Thanks!
The best way is to group the items in a SQL query.
So in you controller you should using groupBy() to grouping the result.
Look at this example:
$itemEntries = $this->em->createQueryBuilder()
->select('e')
->from('AppBundle:Entry', 'e')
->groupBy('e.bidId')
->getQuery()
->getResult();

Mistake Arguments must be separated by a comma. Unexpected token "punctuation" of value

{% for item in product %}
<tr>
<td class="col-lg-5" > <h5> {{ item.tensp}}</h5></td>
<td class="col-lg-12"> {{ item.thanhphan}}</td>
<td class="col-lg-12"> {{ item.gia}}</td>
line 19 <td class="col-lg-12"> <img src="{{asset('/bundles/image/'{item.hinh})}}" alt=""/></td>
</tr>
{% endfor %}
I got this error message in Symfony Arguments must be separated by a comma. Unexpected token "punctuation" of value "{" ("punctuation" expected with value ",") in SP\findall.html.twig at line 19.
how can i fix it
Try concat string with ~ operator.
{% for item in product %}
<tr>
<td class="col-lg-5" ><h5> {{ item.tensp}}</h5></td>
<td class="col-lg-12">{{ item.thanhphan}}</td>
<td class="col-lg-12">{{ item.gia }}</td>
<td class="col-lg-12"><img src="{{ asset('/bundles/image/' ~ item.hinh)}}" alt=""/></td>
</tr>
{% endfor %}

how use parameters in the path-string

I am using Symfony2 and TWIG. With "path" I will open a second page and set some parameters.
{% set place = "The City" %}
<tr>
<td class="tdstellenangebot_zelle">
<a href="#" onclick="anzeige_job('{{ path("_anzeige_job",{kznr:102,ort:"unseren Standort in " {{ place }} ,filiale:1} ) }}')">
The jobdescription
</a>
</td>
<td class="tdstellenangebot_zelle textBold">{{ place }} </td>
</tr>
But the script dont work.
How can I set the place in the path with the variable ?
Thanks alot for your help.
You need simple concatenation:
{% set place = "The City" %}
<tr>
<td class="tdstellenangebot_zelle">
<a href="#" onclick="anzeige_job('{{ path("_anzeige_job", { kznr: 102, ort:"unseren Standort in " ~ place, filiale: 1 }) }}')">
The jobdescription
</a>
</td>
<td class="tdstellenangebot_zelle textBold">{{ place }} </td>
</tr>
Take a look at tilde sign ~. It is like + in JavaScript and . in PHP and is used to concatenate strings.

Need advices with Symfony2

I've understood the routing principle consisting in creating routes and call them from twig templates.
When calling, we can pass parameters to the route which will be included in the url.
I'm in the following case, I have an object called "Object" and each object can belong to other objects called "Category".
In my twig template, I display all my objects line by line (each row contains the object information and a checkbox to select it).
I have also a button "send", I'd like to click this button and edit all the selected objects.
However I don't think I can do this with a route because I don't know by advance how many elements will be selected (so I don't know the number of parameters to the route).
I'd like to know how you would do this.
Sorry for the tardive response, I have the following code in my twig tempalte :
<table class="table table-bordered table-condensed table-stripped">
<tr>
<td> Delete </td>
<td> Title </td>
<td> Date added </td>
<td> Description </td>
<td> </td>
</tr>
{% for link in links %}
<tr>
<td>
<a class="btn" href="{{ path('ProjectTestBundle_deleteLink', {'idLink': link.id}) }}"><i class="icon-trash"></i></a>
</td>
<td> <a>{{link.title}}</a> </td>
<td> {{link.dateAjout|date('Y-m-d H:i:s')}} </td>
<td> {{link.description}} </td>
<td>
<input id="{{link.id}}" type="checkbox"">
</td>
</tr>
{% endfor %}
</table>
<a class="btn">
<i class="icon-edit"></i>
Add selected links to a theme
</a>
What I'd like to is to put a href attribute there
<a href="" class="btn">
<i class="icon-edit"></i>
Add selected links to a theme
</a>
and call a path with all the links selected with the checkbox.

Resources