Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>So you want to show the first 22, then your custom block title, then the rest of the products?</p> <p>Take this line:</p> <pre><code>@foreach (var item in Model) </code></pre> <p>and replace with these two:</p> <pre><code>@int i = 0; @for (i = 0; i &lt; Model.Count() &amp;&amp; i &lt; 22; i++) </code></pre> <p>and also:</p> <pre><code>@Html.Partial("_ProductBox", item) </code></pre> <p>with</p> <pre><code>@Html.Partial("_ProductBox", Model[i]) </code></pre> <p>This will cause the view to output only up until the first 22 products, after which you can insert your block header with the following:</p> <pre><code>&lt;div class="item-box"&gt; My block title sentence! &lt;/div&gt; </code></pre> <p>and then output the remainder of the products:</p> <pre><code>@for (i = i; i &lt; Model.Count(); i++) { &lt;div class="item-box"&gt; @Html.Partial("_ProductBox", Model[i]) &lt;/div&gt; } </code></pre> <p>This works because we kept track of how many products were already rendered in the variable <code>i</code>, and then we continue from there in the collection of products found in the model (if there's more than 22 of them).</p> <p>Note that the code will still output your block title even if there are less than 22 products, at the very end of the list.</p> <p>So the final changes altogether are:</p> <pre><code>@model IList&lt;ProductOverviewModel&gt; @using Nop.Web.Models.Catalog; @if (Model.Count &gt; 0) { &lt;div class="product-grid home-page-product-grid"&gt; &lt;div class="title"&gt; &lt;strong&gt;@T("HomePage.Products")&lt;/strong&gt; &lt;/div&gt; @int i = 0; @for (i = 0; i &lt; Model.Count() &amp;&amp; i &lt; 22; i++) { &lt;div class="item-box"&gt; @Html.Partial("_ProductBox", Model[i]) &lt;/div&gt; } &lt;div class="item-box"&gt; My block title sentence! &lt;/div&gt; @for (i = i; i &lt; Model.Count(); i++) { &lt;div class="item-box"&gt; @Html.Partial("_ProductBox", Model[i]) &lt;/div&gt; } &lt;/div&gt; } </code></pre> <p>EDIT: Sorry I forgot to change the reference to the individual products to be array-based, using Model[i] instead of item. See my changes above.</p>
    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.
    1. VO
      singulars
      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