Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to attach counter variable on field in twig file?
    primarykey
    data
    text
    <p>I make a table in twig file and i want to populate data through loop but my fields name same so i want to attach a counter variable along each field name,how i do this?</p> <p>Here is my code:</p> <pre><code>&lt;div id="table"&gt; &lt;table class="table table-bordered"&gt; &lt;thead&gt; &lt;tr&gt; &lt;th style="text-align:left; width:120px;"&gt;Item&lt;/th&gt; &lt;th style="text-align:left; width:200px;"&gt;Description&lt;/th&gt; &lt;th style="width:100px;"&gt;Unit Cost&lt;/th&gt; &lt;th style="text-align:right; width:60px;"&gt;Qty&lt;/th&gt; &lt;th style="text-align:left; width:100px;"&gt;Tax&lt;/th&gt; &lt;th style="text-align:left; width:100px;"&gt;Tax&lt;/th&gt; &lt;th style="text-align:right; width:100px;"&gt;Line Total&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; {% for items in itemdata %} &lt;tr&gt; &lt;td colspan=7 width=800&gt; &lt;select class="items" name="items" style="width:127px; float:left;" id="items"&gt;&lt;option value="1" selected="selected" disabled="disabled"&gt;&lt;/option&gt;&lt;/select&gt; &lt;textarea name="description" id="description" class="description" style="float:left; display: block; height: 30px; width:209px; border-radius:0px; margin: -1px 1px 0;"&gt;{{ items.description }}&lt;/textarea&gt; &lt;input type="text" name="unitprice" id="unitprice" class="unitprice" value="{{ items.unitPrice }}" style="float:left; display:block; height:30px; width:106px; border-radius:0px; margin:-1px -1px 0;"&gt; &lt;input type="text" name="quantity" id="quantity" class="quantity" value="{{ items.quantity }}" style="float:left; display: block; height: 30px; width:64px; border-radius:0px; margin: -1px 1px 0;"&gt; &lt;select name="firsttax" id="firsttax" style=" float:left; display: block; height: 31px; width:106px; border-radius:0px; margin: -2px -1px 0;"&gt;&lt;option value="1" selected="selected" &gt;&lt;/option&gt;&lt;/select&gt; &lt;select name="secondtax" id="secondtax" style="float:left; display: block; height: 31px; width:107px; border-radius:0px; margin: -2px 0px 0;"&gt;&lt;option value="1" selected="selected"&gt;&lt;/option&gt;&lt;/select&gt; &lt;input type="text" name="linetotal" id="linetotal" class="linetotal" value="{{ items.linetotal }}" placeholder="0.00" readonly style="float:right; display: block; height: 31px; width:107px; border-radius:0px; background-color: #F0F0F0; text-align:right; margin: -31px -1px 0;"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;input type="hidden" id="itemscounter" name="itemscounter" value=""/&gt; {% endfor %} </code></pre> <p>My fields name same here is screenshot:</p> <p><img src="https://i.stack.imgur.com/aVS7a.png" alt="enter image description here"> </p> <p>How to change field names like description,description2,description3,description4 and so on.....</p> <p>Where </p> <pre><code>itemscounter value = number of rows </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload