Why the following error is coming in smarty foreach loop? - foreach

Following is my code of foreach loop in smarty template:
{if $question_detail.question_has_sub_ques=='yes' && $question_detail.sub_question}
{foreach from=$question_detail.sub_question item=sub_ques_ans key=sub_ques_no}
<tr class="oddRow">
<td class="question">
<h4><strong>Sub-question {$page_question_no+1}.{$sub_ques_no+1}</strong></h4>
<ul class="options">
<li><span>{$sub_ques_ans.question_text}</span></li>
</ul>
</td>
<td class="question-id">QUE{$sub_ques_ans.question_id}</td>
</tr>
{if $sub_ques_ans.question_file!=''}
<tr>
<td valign="top" colspan="2">
<img src="{$ques_thum_image_path}{$sub_ques_ans.question_id}_{$sub_ques_ans.question_file}">
</td>
</tr>
{/if}
{if $question_detail.sub_question_answer_{$page_question_no+1}}
<tr class="question_answer evenRow">
<td class="question">
<p class="answers"><strong>Answers</strong></p>
<ol class="options">
**{foreach from=$question_detail.sub_question_answer_{$page_question_no+1} item=sub_ans key=sub_ans_no}**
<li>
{if $sub_ans.answer_is_right==1} {assign var='correct_sub_ans' value=$sub_ans_no+1} {/if}
{if $sub_ans.answer_text!=''}{$sub_ans.answer_text}{/if}<br />
{if $sub_ans.answer_file!=''}<img src="{$ans_thumb_img_path}{$sub_ans.answer_id}_{$sub_ans.answer_file}" >{/if}
</li>
{/foreach}
</ol>
<p class="correct-answer"><strong>Correct Answer Option : </strong>{$correct_sub_ans}</p>
</td>
<td class="question-id"> </td>
</tr>
{/if}
{/foreach}
{/if}
I'm getting error as follows:
Fatal error: Smarty error: [in question-details.tpl line 66]:
syntax error: foreach: missing 'item' attribute (SmartyCompiler.php, line 1179) in /var/www/eprime/ocn/core/libs/Smarty.php on line 1095
And the line no.66 in my code is:
{foreach from=$question_detail.sub_question_answer_{$page_question_no+1} item=sub_ans key=sub_ans_no}
Can anyone help me in correcting this error? Any kind of help would be highly appreciated.

Try this
{assign var="condition" value="{$question_detail.sub_question_answer}_{$page_question_no+1}"}
{foreach from=$condition item=sub_ans key=sub_ans_no}
// do your code
{/foreach}

Related

Table dropdown with bootstrap 5 not working

I am trying to show product items when button order detail is pressed, but its not working in any way I tried, it's possible to make it work with bootstrap 5 or I have to do it with javascript ?
Useless information for "It looks like your post is mostly code; please add some more details." : In the first foreach I am displaying information from the order, then the second foreach is retrieving product id and quantity from a different table that contain order id and the third foreach is getting product where id from the second foreach in order to display product details
<table class="table border">
<thead>
<tr>
<th class="h4" style="width: 18%">Order Number</th>
<th class="h4">Date</th>
<th class="h4">Total</th>
<th class="h4">Status</th>
<th class="h4"></th>
<td></td>
</tr>
</thead>
<tbody>
<tr>
<?php
foreach ($order as $row_order) {
$order_status = intval($row_order->status);
?>
<td class="fw-bold">{{ $row_order->id }}</td>
<td class="fw-bold">{{ $row_order->added_on }}</td>
<td class="fw-bold">{{ $row_order->order_total }} $</td>
<td class="fw-bold"><?php if($order_status == 0){ ?>
Not Paid
<?php }elseif ($order_status == 1) { ?>
Paid
<?php }elseif ($order_status == 2) { ?>
Shipped
<?php }elseif ($order_status == 3) { ?>
Delivered
<?php } ?>
</td>
<td></td>
{{-- <td><a class="btn btn-primary" href="">Order Detail</a></td> --}}
<div class="btn-group">
<td>
<button class="btn btn-primary dropdown-toggle" type="button" id="dropdownMenuButton" data-bs-toggle="dropdown" aria-expanded="false">
Order Detail
</button>
</td>
#foreach (\App\Models\Order_product_size_color::where('order_id', '=', $row_order->id)->get() as $order_variant)
#foreach (\App\Models\Product_size_color::where('id', '=', $order_variant->product_size_color_id)->get() as $variant)
<div class="dropdown-menu">
<td class="border-0 p-0 dropdown-item">
<tr>
<td class="border-0"><img class="rounded" src="{{ asset('storage/'. $variant->image1->product_image) }}" alt="" style="width: 80px; height: 90px;"></td>
<td class="fw-bold border-0">{{ $variant->product->product_name }}</td>
<td class="border-0">{{ $order_variant->count }} products</td>
<td class="fw-bold border-0">Size: {{ $variant->size->size_name }}</td>
<td class="fw-bold border-0">Color: {{ $variant->color->color_name }}</td>
<td class="fw-bold border-0">${{ $variant->product->price }}</td>
</tr>
</td>
</div>
#endforeach
#endforeach
</div>
<tr>
<td class="fw-bold">Delivery Address:</td>
<td class="fw-bold">{{ $row_order->address }}</td>
</tr>
</tr>
<?php }//end foreach ?>
</tbody>
</table>

How to retrieve column that is dynamically displayed in a table form

I would like to retrieve each row of a datatable that is dynamically created. I created a form with the post method to get these rows but I don't how what to write in my view function to have these in a panda DataFrame.
<form action="{%url 'livedb_model:validation' property.id roomtype.id %}?normal_price={{normal_price}}&week_day_multi={{week_day_multi}}&week_end_multi={{week_end_multi}}&max_discount={{max_discount}}&max_markup={{max_markup}}&coccCategory={{coccCategory}}&agressiveness={{agressiveness}}" method="post">
{% csrf_token %}
<input class='btn btn-primary btn-large btn-block align-self-center'type='submit' value='submit'>
<div id="datatable" class="table-editable align-self-stretch">
<table class="table table-bordered table-responsive-md table-striped text-center">
<tr>
<th class="text-center">Date</th>
<th class="text-center">Availability</th>
<th class="text-center">Current Price</th>
<th class="text-center">Current Occupancy</th>
<th class="text-center">Advised Price</th>
</tr>
{% for day in invdf.itertuples %}
<tr>
{% if day.availability.room %}
<td class="pt-3-half" id='date'>{{day.date|date:'M d,Y'}}</td>
<td class="pt-3-half">{{day.allotment}}</td>
<td class="pt-3-half">{{day.price|floatformat:2}}</td>
<td class="pt-3-half">{{day.occupancy|floatformat:2}}</td>
<td class="pt-3-half" id='price_advised' contenteditable="true">{{day.price_advised|floatformat:2}}</td>
{% else %}
<td class="pt-3-half" id='date'>{{day.date|date:'M d,Y'}}</td>
<td class="pt-3-half">{{day.allotment}}</td>
<td class="pt-3-half">{{day.price|floatformat:2}}</td>
<td class="pt-3-half">{{day.occupancy|floatformat:2}}</td>
<td class="pt-3-half" id='price_advised' contenteditable="true">{{day.price_advised|floatformat:2}}</td>
{% endif %}
</tr>
{% endfor%}
</div>
</form>
For instance I would like to write something like in my view:
def validation(request,id,rt_id):
if request.method=='POST':
price_advised=request.POST.get(ADVISED PRICE COLUMN)
Could you help me on this?
Thank you
you can use javascript add parameter before submitting form

ASP.NET call an #id from a tag

I have a little problem - I build a shopping cart checkout with 4 steps (with stepper and links to partial views).
Now I have to call a special #id (the attribute of tags) from the redirectToAction...
How is this possible?
the thing is - I'm in step 2 (partial view) and call an actionresult, which redirect me to the "main view" - but I have to go to the 2nd or 3rd step.
Is there a way how to handle this?
Tried already to overload the button, so the href call the link and an onclick function() calls the actionresult, but this is not possible
Also tried to give the #id as a route value, but it seems doesn't work...
<script>
function goBack() {
window.history.back();
}
//Initialize tooltips
//$('.nav-tabs > li a[title]').tooltip();
//Wizard
$('a[data-toggle="tab"]').on('show.bs.tab', function (e) {
var $target = $(e.target);
if ($target.hasClass('disabled')) {
return false;
}
});
$(".next-step").click(function (e) {
var $active = $('.wizard .nav-tabs .nav-item .active');
var $activeli = $active.parent("li");
$($activeli).next().find('a[data-toggle="tab"]').removeClass("disabled");
$($activeli).next().find('a[data-toggle="tab"]').click();
});
$(".prev-step").click(function (e) {
var $active = $('.wizard .nav-tabs .nav-item .active');
var $activeli = $active.parent("li");
$($activeli).prev().find('a[data-toggle="tab"]').removeClass("disabled");
$($activeli).prev().find('a[data-toggle="tab"]').click();
});
</script>
<form class="form cf">
<div class="wizard">
<!-- ============================================================ NAVIGATION ============================================================ -->
<div class="wizard-inner">
<div class="connecting-line"></div>
<ul class="nav nav-tabs" role="tablist">
<!-- ======================================== Schritt 1 - Warenkorb ======================================== -->
<li role="presentation" class="nav-item">
<a href="#step1" data-toggle="tab" aria-controls="step1" role="tab" title="Step 1" class="nav-link active navigation">
<span class="round-tab">
<i class="fa fa-lg fa-shopping-cart"></i>
</span>
</a>
</li>
<!-- ======================================== Schritt 2 - Ausleihdatum ======================================== -->
<li role="presentation" class="nav-item">
<a href="#step2" data-toggle="tab" aria-controls="step2" role="tab" title="Step 2" class="nav-link navigation disabled" id="schritt">
<span class="round-tab">
<i class="fa fa-lg fa-calendar-check-o"></i>
</span>
</a>
</li>
<!-- ======================================== Schritt 3 - Rechnung- und Lieferadresse ======================================== -->
<li role="presentation" class="nav-item">
<a href="#step3" data-toggle="tab" aria-controls="step3" role="tab" title="Step 3" class="nav-link navigation disabled">
<span class="round-tab">
<i class="fa fa-lg fa-address-card-o"></i>
</span>
</a>
</li>
<!-- ======================================== Schritt 4 - Bezahlmöglichkeit ========================================
<li role="presentation" class="nav-item">
<a href="#step4" data-toggle="tab" aria-controls="step4" role="tab" title="Step 4" class="nav-link disabled">
<span class="round-tab">
<i class="fa fa-lg fa-money"></i>
</span>
</a>
</li>
<!-- ======================================== Schritt 5 - Abschluss ======================================== -->
<li role="presentation" class="nav-item">
<a href="#step4" data-toggle="tab" aria-controls="step4" role="tab" title="Step 4" class="nav-link disabled navigation">
<span class="round-tab">
<i class="fa fa-check"></i>
</span>
</a>
</li>
</ul>
</div>
<!-- ============================================================ CONTENT ============================================================ -->
<!-- ======================================== Schritt 1 - Warenkorb ======================================== -->
<div class="tab-content ">
<div class="tab-pane active text-center " role="tabpanel" id="step1">
<h2>Warenkorb</h2>
<div class="row">
</div>
#if (Model.VmWarenkorbIndexListe.Count == 0)
{
<br />
<br />
<h1 class="text-center">Leider haben Sie noch keine Bücher im Warenkorb :-(</h1>
<br />
<h2 class="text-center">Hier können Sie nach Büchern suchen :-)</h2>
}
else
{
<div class="container">
<table id="cart" class="table table-hover table-condensed ">
<thead>
<tr>
<th></th>
<th style="width:40%" class="h4 text-left">#Html.DisplayName("Titel")</th>
<th class="text-center h5" style="width:3%">#Html.DisplayName("Ausgabe")</th>
<th class="text-center h5" style="width: 20%">#Html.DisplayName("ISBN")</th>
<th class="text-center h5" style="width:10%">#Html.DisplayName("Preis")</th>
<th class="text-center h5">#Html.DisplayName("Anzahl")</th>
<th class="text-center h5">#Html.DisplayName("Zeilenpreis")</th>
<th></th>
</tr>
</thead>
<tbody class="border-bottom">
#foreach (var buch in Model.VmWarenkorbIndexListe)
{
<tr>
<td data-th="Bild" class="zoom">
<img src="#buch.BildPfad" alt="#buch.BildAltText" width="70" onclick="location.href = '#(Url.Action("Detail", "Buch", new { buchId = buch.Id }))'" />
</td>
<td data-th="Buch" class="align-middle" data-toggle="tooltip" data-placement="bottom" title="Für Beschreibung bitte klicken">
<h6 class="nomargin text-left" data-toggle="collapse" data-target="#buch">#buch.Titel</h6>
<p class="collapse" id="buch">Quis aute iure reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Lorem ipsum dolor sit amet.</p>
</td>
<td data-th="Ausgabe" class="text-center align-middle h6">#buch.Ausgabe</td>
<td data-th="ISBN" class="text-center align-middle h6">#buch.Isbn</td>
<td data-th="Preis" class="text-center align-middle h6">#buch.PreisProTag.ToString("F2") €</td>
<td data-th="Anzahl" class="text-center align-middle h6">#buch.Anzahl</td>
<td data-th="Zeilenpreis" class="text-right align-middle h6">#buch.ZeilenPreisProTag.ToString("F2") €</td>
<td class="actions align-middle" data-th="">
<a class="btn btn-outline-danger " href="/Warenkorb/Entfernen?buchId=#buch.Id&anzahl=1" role="button" aria-expanded="false">
<i class="fa fa-lg fa-minus-square"></i>
</a>
<a class="btn btn-danger " href="/Warenkorb/Entfernen?buchId=#buch.Id&anzahl=#buch.Anzahl" role="button" aria-expanded="false">
<i class="fa fa-lg fa-cart-arrow-down"></i>
</a>
</td>
</tr>
}
</tbody>
<tfoot>
<tr>
<td colspan="5"></td>
<td class="hidden-xs"><strong class="h4 text-primary">Gesamtpreis </strong></td>
<td class="hidden-xs text-right"><strong class="h4 text-primary"> #Model.VmWarenkorbIndexListe.Sum(s => s.ZeilenPreisProTag).ToString("F2") €</strong></td>
<td></td>
</tr>
<tr>
<!-- ======================================== Schritt 2 - Ausleihdatum ======================================== -->
<td> <a onclick="goBack()" class="btn btn-warning "><i class="fa fa-angle-left"></i> Weiter einkaufen</a></td>
<td colspan="6"></td>
<td class="wizard-inner">
Jetzt Bestellen <i class="fa fa-angle-right"></i>
</td>
</tr>
</tfoot>
</table>
</div>
}
</div>
<!-- ======================================== Schritt 2 - Ausleihdatum ======================================== -->
#Html.Partial("_Bestellen", Model)
<!-- ======================================== Schritt 3 - Rechnung- und Lieferadresse ======================================== -->
#Html.Partial("_Rechnungsdaten", Model)
<!-- ======================================== Schritt 4 - Bezahlmöglichkeit ========================================
<div class="tab-pane" role="tabpanel" id="step4">
<h1 class="text-md-center">Step 4</h1>
<div class="row">
</div>
<ul class="list-inline text-md-center">
<li><button type="button" class="btn btn-lg btn-common next-step next-button">Next Step</button></li>
</ul>
</div>
-->
#Html.Partial("_Danke")
</div>
</div>
</form>
here is the Main View
and here is a partial view
<div class="tab-pane text-center" role="tabpanel" id="step2">
<h2>Ihre Bestellung </h2>
<div class="row">
#using (Html.BeginForm("Bestellen", "Warenkorb", FormMethod.Post))
{
<div class="container">
<div></div>
<table id="cart" class="table table-hover table-condensed ">
<thead>
<tr>
<th style="width:20%" class="h4 text-left">#Html.DisplayName("Titel")</th>
<th class="text-center h5" style="width:20%">#Html.DisplayName("ISBN")</th>
<th class="text-left h5" style="width: 20%">#Html.DisplayName("Autoren")</th>
<th class="text-center h5" style="width: 5%">#Html.DisplayName("Ausgabe")</th>
<th class="text-center h5">#Html.DisplayName("Anzahl")</th>
<th class="text-center h5">#Html.DisplayName("Zeilenpreis")</th>
<th class="text-center h5">
#Html.DisplayName("Rückgabedatum")
</th>
</tr>
</thead>
<tbody class="border-bottom">
#foreach (var buch in Model.VmBestellen.Warenkorb)
{
<tr>
<td data-th="Buch" class="align-middle">
<h6 class="nomargin text-left">#buch.Titel</h6>
</td>
<td data-th="ISBN" class="text-center align-middle h6">#buch.ISBN</td>
<td data-th="Autoren" class="align-middle h6">
#foreach (var autor in buch.Autoren)
{
<span>#autor<br /></span>
}
</td>
<td data-th="Ausgabe" class="text-center align-middle h6">#buch.Ausgabe</td>
<td data-th="Anzahl" class="text-center align-middle h6">#buch.Anzahl</td>
<td data-th="Zeilenpreis" class="text-right align-middle h6">#buch.ZeilenPreisProTagNetto.ToString("F2") €</td>
<td data-th="Datum">
#Html.EditorFor(model => model.VmBestellen.RueckgabeDatum, new { htmlAttributes = new { #type = "date", #name = "rueckgabedatum", #value = Model.VmBestellen.RueckgabeDatum.ToString("dd.MM.yyyy"), #class = "form-control" } })
#Html.ValidationMessageFor(model => model.VmBestellen.RueckgabeDatum, "", new { #class = "text-danger" })
<button type="submit" formmethod="get"> Datum ändern</button>
</td>
</tr>
}
</tbody>
<tfoot>
<tr>
<td colspan="3" class="hidden-xs"></td>
<td class="hidden-xs" colspan="2"><strong class="h5 ">Preis <strong class="h6">(exkl. Mwst)</strong> </strong></td>
<td class="hidden-xs text-right"><strong class="h5 "> #Model.VmBestellen.Warenkorb.Sum(s => s.ZeilenPreisProTagNetto).ToString("F2") €</strong></td>
<td class="hidden-xs"> <strong class="h5">Beginn: <bdi class="text-primary">#DateTime.Now.ToShortDateString() </bdi></strong></td>
</tr>
<tr>
<td colspan="3" class="hidden-xs"></td>
<td class="hidden-xs" colspan="2"><strong class="h6 ">Rabatt </strong></td>
<td class="hidden-xs text-right"><strong class="h6 "> - Rabatt -</strong></td>
<td class="hidden-xs"><strong class="h5">Ende: <bdi class="text-primary ">#Model.VmBestellen.RueckgabeDatum.ToShortDateString() </bdi></strong></td>
</tr>
<tr>
<td colspan="3" class="hidden-xs"></td>
<td class="hidden-xs" colspan="2"><strong class="h6 ">Mwst </strong></td>
<td class="hidden-xs text-right"><strong class="h6 "> #Model.VmBestellen.MwstBetrag.ToString("F2") €</strong></td>
<td class="hidden-xs"><strong class="h5"> Tage Gesamt: <bdi class="text-primary">XX</bdi> </strong> </td>
</tr>
<tr>
<td colspan="3" class="hidden-xs"></td>
<td class="hidden-xs" colspan="2"><strong class="h4 text-primary">Preis <strong class="h6 text-primary">(inkl. Mwst)</strong> </strong></td>
<td class="hidden-xs text-right"><strong class="h4 text-primary"> #Model.VmBestellen.GesamtpreisBrutto.ToString("F2") €</strong></td>
<td></td>
</tr>
<tr>
<!-- ======================================== Schritt 3 - Abschluss ========================================-->
<td > <a onclick="goBack()" class="btn btn-warning btn-block "><i class="fa fa-angle-left"></i> Zurück zum Warenkorb</a></td>
<td colspan="5"></td>
<td class="wizard-inner">
Bestellung abschließen <i class="fa fa-angle-right"></i>
</td>
</tr>
</tfoot>
</table>
</div>
}
</div>
</div>
here is the a href - which calls at the moment only a link - but i would need to call the link AND with the same click call an POST-ActionResult
i thought i could call the POST ActionResult and from there Redirect to a specific #id

How to expand and collapse table row using Bootstrap Accordion and ASP.NET MVC?

I want to expand and collapse table row using Bootstrap Accordion.
Currently, if I click on any row, it expands and collapse. But what I want is that, if I click on second row then first row should collapse if it is expanded then and so on.
<div class=" panel-body">
<table class="table">
#foreach (var item in Model)
{
<tr>
<td class="accordion-toggle" data-toggle="collapse" data-target="#AA_#(item.Id)">
<button class="bb" type="button">
#Html.Raw(item.H)
</button>
</td>
<td>
#Html.Raw(item.E)
</td>
</tr>
<tr>
<td id="AA_#(item.Id)" class="accordion-body collapse">
<table>
<tr>
<td>
#Html.Raw(item.D)
</td>
<td>
#Html.Raw(item.B)
</td>
</tr>
</table>
</td>
</tr>
}
</table>
</div>
I researched my problem on SO and found one solution provided by #tmg on here. Many thanks to #tmg. I followed the same in my scenario and it worked for me.
<div class="panel-body">
<table class="table">
#foreach (var item in Model)
{
<tr class="accordion-toggle" data-toggle="collapse" data-target="#AA_#(item.Id)">
<td>
<button class="bb" type="button">
#Html.Raw(item.H)
</button>
</td>
<td>
#Html.Raw(item.E)
</td>
</tr>
<tr>
<td class="hiddenRow">
<div class="accordian-body collapse" id="AA_#(item.Id)">
<table>
<tr>
<td>
#Html.Raw(item.D)
</td>
<td>
#Html.Raw(item.B)
</td>
</tr>
</table>
</div>
</td>
</tr>
}
</table>
</div>
And added JQuery to collapse and toggle table row
$('.table .accordian-body').on('show.bs.collapse', function () {
$(this).closest("table")
.find(".collapse.in")
.not(this)
.collapse('toggle')
})
Added Style for hiddenRow
.hiddenRow {
padding: 0 !important;
}

How to implement bootstrap accordion in table in MVC?

I want to implement bootstrap accordion in my application. Currently, If I click on any rows, it gives me first #Html.Raw(item.D) and #Html.Raw(item.B).
What i want is that, if i click on 2nd row then its respective #Html.Raw(item.D) and #Html.Raw(item.B) should displayed and so on.
Please suggest me where I am going wrong.
<div class="panel-body">
<table class="table">
#foreach (var item in Model)
{
<tr class="accordion-toggle" data-toggle="collapse" data-target="#12345-cores">
<td align="left">
#Html.Raw(item.H)
</td>
<td align="right">
#Html.Raw(item.E)
</td>
</tr>
<tr>
<td class="accordion-body collapse" id="12345-cores">
<table>
<tbody>
<tr>
<td>
#Html.Raw(item.D)
</td>
<td></td>
<td>
#Html.Raw(item.B)
</td>
</tr>
</tbody>
</table>
</td>
</tr>
}
</table>
You need to specify id uniquely, to do so you need to append raw id(or something unique for each row) to id and data-target attributes,
<div class="panel-body">
<table class="table">
#foreach (var item in Model)
{
<tr class="accordion-toggle" data-toggle="collapse" data-target="#12345-cores#(item.id)">
<td align="left">
#Html.Raw(item.H)
</td>
<td align="right">
#Html.Raw(item.E)
</td>
</tr>
<tr>
<td class="accordion-body collapse" id="12345-cores#(item.id)">
<table>
<tbody>
<tr>
<td>
#Html.Raw(item.D)
</td>
<td></td>
<td>
#Html.Raw(item.B)
</td>
</tr>
</tbody>
</table>
</td>
</tr>
}
</table>
updated : data-target="#12345-cores#(item.id) & id="12345-cores#(item.id)"

Resources