0

We just recently tested upgrading from M2.2.4 to M2.3.7 and have ironed out most of the issues, however when trying to load a page, we get the following error:

Fatal error: Uncaught Error: Object of class Magento\Framework\View\Page\Title could not be converted to string in /app/code/CleverSoft/Base/Model/Renderer.php:141 Stack trace: #0 /app/code/CleverSoft/Base/Model/Renderer.php(141): str_replace(Array, Array, '<meta name="%na...') #1 /app/code/CleverSoft/Base/Model/Renderer.php(112): CleverSoft\Base\Model\Renderer->renderMetadata() #2 /vendor/magento/framework/View/Result/Page.php(250): CleverSoft\Base\Model\Renderer->renderHeadContent() #3 /vendor/magento/framework/View/Result/Layout.php(171): Magento\Framework\View\Result\Page->render(Object(Magento\Framework\App\Response\Http\Interceptor)) #4 /vendor/magento/framework/Interception/Interceptor.php(58): Ma in /app/code/CleverSoft/Base/Model/Renderer.php on line 141

The function it is referring to within Renderer.php is:

public function renderMetadata()
    {
        $result = '';
        foreach ($this->pageConfig->getMetadata() as $name => $content) {
            $metadataTemplate = $this->getMetadataTemplate($name);
          if (!$metadataTemplate) {
                continue;
            }
            $content = $this->processMetadataContent($name, $content);
            if ($content) {
               $result .= str_replace(['%name', '%content'], [$name, $content], $metadataTemplate);
            }
        }
        return $result;
    }

With the mentioned line 141 being $result .= str_replace(['%name', '%content'], [$name, $content], $metadataTemplate);

Just playing with it and changing the code to:

public function renderMetadata()
    {
        $result = '';
        return $result;
    }

Allows the pages to load but, some elements end up broken like the navigation menus and whatnot. The above is not a solution, so anyone has any ideas. What did I do to allow for the object to be converted to a string?

Thanks!

3 Answers 3

1
+50

You need to try this code.

protected $emailfilter;

public function __construct(
        .....
        \Magento\Email\Model\Template\Filter $filter,
        .....)
    {
        $this->emailfilter = $filter;
    }

public function renderMetadata()
    {

        $result = '';
        foreach ($this->pageConfig->getMetadata() as $name => $content) 
        {
            $metadataTemplate = $this->getMetadataTemplate($name);
            if(!$metadataTemplate) 
            {
               continue;
            }
            $content = $this->processMetadataContent($name, $content);
            if ($content) 
            {
               $this->emailfilter->setVariables(['%name' => $name,'%content' => $content]);
               $result = $this->emailfilter->filter($metadataTemplate);
            }
         }
    return $result;
    }
4
  • Thanks for helping! I implemented the protected designation, the __construct listings, however not sure how to implement the renderMetadata() function. I first tried with none of the previous function and just using yours as displayed, but it gave Undefined variable: name on $this->emailfilter->setVariables(['%name' => $name,'%content' => $content]); -- I then tried a few variations of mixing in your code with the original function with no success. Is there anything else to add to the renderMetadata() function?
    – ne0nlight
    Nov 9, 2021 at 18:16
  • I update the code kindly check and let me know. Nov 10, 2021 at 3:59
  • Thank you! Your changes allowed for the page to load, however it didn't end up displaying the content much like when I just changed the renderMetadata() to only having $result = ''; return $result; inside it -- no error, just no block either. The Menu isn't displaying and the footer isn't displaying so I assume it's having an issue loading these elements as widgets. Any ideas? For instance, the menu that isn't loading comes in via this: {{widget type="CleverSoft\CleverMegaMenus\Block\Widget\Megamenu" menu="main_menu"}} Thanks as always!
    – ne0nlight
    Nov 11, 2021 at 14:29
  • That is from third party extension so that need to check what actually problem there. If answer help you to resolve the issues please accept as solution and upvote so it will help other in community. Nov 12, 2021 at 5:20
0

What about trying something like this for each of your name and content ? Not sure about the syntax but here is the idea

if(get_class($name) == 'Magento\Framework\View\Page\Title'){
    $realName = $name->get();
}
0

Maybe some custom module affect to value of title. I think it's a good idea to debug to see what the value of title is.

Your Answer

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

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