Miva Merchant Development by Scot's Scripts

STRING: Truncate a String/Product Description at a Space

Miva Knowledge Base
STRING: Truncate a String/Product Description at a Space

WARNING:

This information is offered "AS IS" for internal reference only. Use at your own risk.
Does AI actually understand your Miva Merchant store? Our smart JSON-LD schema generator makes sure it does. Contact us to get started. (more info)

STRING: Truncate a String/Product Description at a Space

Scot Ranney • September 10, 2026


THIS CODE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED;
THE AUTHOR DISCLAIMS ALL LIABILITY FOR ANY DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR STORE DISRUPTIONS ARISING FROM ITS USE.


MivaScript INDEXOF(...) function is better than substring for truncating a product description than SUBSTRING(...)

<mvt:if expr="len(l.settings:product:descrip) GT 256">
<mvt:assign name="l._pos" value="indexof( ' ', l.settings:product:descrip, 254)" />
<mvt:assign name="l.settings:_descrip" value="substring(l.settings:product:descrip,1,l._pos)" />
<mvt:if expr="len(l.settings:_descrip) LE 0">
&mvt:product:descrip;
<mvt:else>
&mvt:_descrip;...
</mvt:if>
<a class="more-link" title="&mvte:product:name;" href="&mvte:product:link;"> (more)</a>
<mvt:else>
&mvt:product:descrip; <a class="more-link" title="&mvte:product:name;" href="&mvte:product:link;">(details...)</a>
</mvt:if>

https://www.scotsscripts.com/mvblog/string-truncate-a-stringproduct-description-at-a-space.html

mvkb_string mvkb_mivascript