I used below code to limit the short description in product page:
1) it truncates all other attributes with text field in product page not only if ($_product->getData('short_description'))
. How make the if to check if this attribute is short_description
then do the task?
2) what should be in <a href="#">Read More</a>
that after clicking on read more it expands the text?
<div class="value" <?php /* @escapeNotVerified */ echo $_attributeAddAttribute;?>>
<?php if ($_product->getData('short_description')) {
$string = strip_tags($_product->getData('short_description'));
if (strlen($string) > 50) {
// truncate string
$stringCut = substr($string, 0, 50);
$string = substr($stringCut, 0, strrpos($stringCut, ' ')).'... <a href="#">Read More</a>';
}
echo $string;
}else {?>
<?php /* @escapeNotVerified */ echo $_attributeValue; }?>
</div>
Best Answer
You have to just overrider
attribute.phtml
file from module-catalog core module.Copy file inside your theme,
app/design/frontend/Vendor/luma/Magento_Catalog/templates/product/view/attribute.phtml