Are there any way in magento to split a string that is too long? Specifically i want product description and in my custom module so i can have a nice javascript ‘read more’ dropdown and keep string lengths tidy
I am possible to do the javascript by myself ok but need help splitting the string in to 2 parts with magento
Ok, first of all Magento does provide a method to do this via its core string helpers’ truncate method – Mage_Core_Helper_String it has a couple of nice features but there is absolutely no reason that you cannot create a basic version of this in plain old php with very little effort using substr. I will show examples of both methods below…
Using php substr
Using the Magento string helper
As mentioned, this helper provides some nice features above the previous example: namely etc string and option to break words or not. I will leave it up to you to explore that method and its options, but as a basic example: