0

I want to display certain CMS pages on categories and products, which the administrator assigns to the category or product. They would appear as cards. Somehow first the title of the CMS page and then as a description let's say 100 initial characters from the content. How to get those first 100 characters from page content?

1 Answer 1

0

You can Try and add this on your phtml. Please do inject the CMS Page model.

$cms = \Magento\Framework\App\ObjectManager::getInstance()->get(\Magento\Cms\Model\Page::class);
$page = $cms->load('home','identifier');

$pageTitle = $page->getTitle();
$pageContent = $page->getContent();
$pageContent = substr($pageContent, 0, 100);

echo '<h3>' . $pageTitle . '</h3>';
echo '<p>' . $pageContent . '...</p>';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.