Limit the amount of text that appears in ProductBox1

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
13 years ago
Because I didn't want any words chopped in half.  It looks for the last space in the first 100 characters of short description and returns everything before that last space.  




if (product.ShortDescription.Length <= 100)  //or whatever length you want
                {
                    lShortDescription.Text = product.ShortDescription;
                }
                else
                {
                    lShortDescription.Text = product.ShortDescription.Substring(0, product.ShortDescription.Substring(0, 100).LastIndexOf(" ")) + "...";
                }
11 years ago
A different way of fixing this issue. I needed a little extra control as to where the teaser pages cut off the short description, instead of a set amount every time. But I didn't want to add a new field to the manager section, so instead used overloaded views which are much easier. So I just add a "[/text]" marker (you can use whatever you want, just update the code accordingly) to the content itself in the admin area, then in the following files.

ProductTemplate.VariantsInGrid.cshtml

Change the model description display line to:

@Html.Raw(Model.ShortDescription.Replace("[/text]",""))

This will keep the tag from showing at the product level. Then for the next file:

_ProductBox.cshtml

Replace the single line where the short description is shown to the following:
@{
    var ShortDescription = Model.ShortDescription;
    if (ShortDescription.IndexOf("[/text]") > 0)
    {
        ShortDescription = ShortDescription.Substring(0, ShortDescription.LastIndexOf("[/text]"));
    }
}  
@Html.Raw(ShortDescription)

Then on your teaser pages (newproducts, search, categories, etc) if you use the "[/text]" in your short description, it will stop showing the content at that point, allowing you to control where it breaks, but the full short description will still show at the product level.

This was done in Nop v2.3
11 years ago
Does anyone know if this was sorted in version 2.80? i.e. if you can manage the number of characters in the product back end?

Seems crazy that you cannot do this easily...
11 years ago
stevied wrote:
Does anyone know if this was sorted in version 2.80? i.e. if you can manage the number of characters in the product back end?

Seems crazy that you cannot do this easily...

Not available out of the box. Try what Geralt suggested above
7 years ago
please use below code

<div>
      @{
                            string x = product.ShortDescription;
                            if (x != null && x.Length > 30)
                            {
                                x = x.Substring(0, 30)+"...";
                            }
                        }
                        @Html.Raw(x)
</div>
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.