- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2019
11:34 AM
09-07-2019
11:34 AM
Magento 2 Block returns value of 1
I have inherited a project that has the following code:
return $this->getLayout() ->createBlock(CategoryBlock::class) ->setData([ 'title' => $title ? sprintf($title, $category->getName()) : null, 'category_id' => $category->getId(), 'description' => $description ? sprintf($description, $category->getName()) : null, ])->toHtml();The description is working by using $block->getDescription() as I would expect. The $block->getTitle() is not returning the value expected, instead it is return the number 1. Can anyone spot the problem as I have tried various things but it is not working. The project has to use 2.2.7 so need to debug in this version.
6x certified Magento Specialist.
Nigel Boulton, Magento Solution Specialist
Nigel Boulton, Magento Solution Specialist
Labels:
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2019
12:08 PM
09-07-2019
12:08 PM
Re: Magento 2 Block returns value of 1
Hello @pinkdigital
Can you use directly class name instead of
CategoryBlock::classe.g
Vendor\Module\Block\Name
Thanks
Binod
Binod
If my answer is useful, please Accept as Solution & give Kudos
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2019
01:26 PM
09-07-2019
01:26 PM
Re: Magento 2 Block returns value of 1
Thanks for your help. It didn't resolve the problem so I had a deeper look in to the code.
The problem was caused by the previous developer returning $this->hasData('title') instead of $this->getData('title'); hence the value of 1 (true).
6x certified Magento Specialist.
Nigel Boulton, Magento Solution Specialist
Nigel Boulton, Magento Solution Specialist