I am completely new in Magento and trying to create a widget that will simply display the selected pages on the frontend.

That's what I have for now in my block class:

public function getPages() {

    // 'selectedpages' is a string with page identifiers: 'no-route','cookie-consent',...
    $selectedPages = explode(',', $this->getData('selectedpages'));

    $pages = array();

    foreach($selectedPages as $singleSelectedPage) {
        // Adding a filter
        $searchCriteria = $this->searchCriteriaBuilder
            ->addFilter('identifier', $singleSelectedPage)

        // Putting all the results into array;
        $pages[] = $this->pageRepositoryInterface->getList($searchCriteria)->getItems();

    return $pages;

In my template:

<?php foreach($block->getPages() as $pageItem) : ?>
    <?php echo $pageItem ?>
<?php endforeach; ?>

The problem is that once I call for the $pages[] array somehow, it throws me a 500 error stating that Allowed memory size of 2147483648 bytes exhausted (tried to allocate 1474314240 bytes).

My memory limits are set to 2G - in nginx configuration, as well as in php.ini, .user.ini, /pub/.user.ini and in all .htaccess (yeah, I know that nginx won't listen to .htaccess).

Doing memory_usage() shows that I am using only about 12Mb BEFORE calling this array.

Update: Converting $pages[] to $pages solves the problem, but only displays the last page, since this all is inside of the foreach loop.

Where the problem may be?

Kind regards

  • may be one of the pages having issue, could you please try to add its manually and see which page having issue.
    – Nits
    Commented Oct 6, 2020 at 12:26
  • What do you mean- add it manually? I tried disabling all them and selecting just one, but still the same issue. Is it the roght logic of displaying a list of links to pages regarding what pages an admin specified from adminhtml?
    – Max Krizh
    Commented Oct 6, 2020 at 18:15


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.