Miva Merchant Development by Scot's Scripts

STRING: Truncate a String/Product Description at a Space

Miva Random Code Trivia

Want to start an online store? We work with you from start to finish, from commerce platform to design to SEO.
Experience counts, and we have a lot.

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)
SEO Audit & Inquiries • News & Updates • SEO for Miva Merchant

STRING: Truncate a String/Product Description at a Space

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.

Scot Ranney • September 10, 2026


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

string mivascript