Description
OK
Preconditions (*)
- Magento 2.3.4
- MacBook Pro (OSX Catalina)
- -and- Linux (Ubuntu)
Steps to reproduce (*)
- Create a new Theme, with web/css folder empty inside.
- Create your default.xml and catalog_product_view.xml
- (Actually, you don't need to worry about re-producing this issue, I attach where exactly the bug is in your code, if you read my notes, you should see that it would fail causing blank-pages or errors sometimes due to double-fault), please see below:
Expected result (*)
- All pages to be rendered or errors reported in the log files. (standard)
Actual result (*)
-
getting an error in: vendor/magento/framework/View/Page/Config/Renderer.php file with missing variable of $template.
-
The issue is to do with the following code (line 429) on the above file, I attach the function below:
protected function renderAssetHtml(\Magento\Framework\View\Asset\PropertyGroup $group)
{
$assets = $this->processMerge($group->getAll(), $group);
$attributes = $this->getGroupAttributes($group);$template = ""; $result = ''; try { /** @var $asset \Magento\Framework\View\Asset\AssetInterface */ foreach ($assets as $asset) { $template = $this->getAssetTemplate( $group->getProperty(GroupedCollection::PROPERTY_CONTENT_TYPE), $this->addDefaultAttributes($this->getAssetContentType($asset), $attributes) ); $result .= sprintf($template, $asset->getUrl()); } } catch (LocalizedException $e) { $this->logger->critical($e); $result .= sprintf($template, $this->urlBuilder->getUrl('', ['_direct' => 'core/index/notFound'])); } return $result;
}
The issue is that in this code, there is an exception occurring (which is fine/expected), however, inside the catch notice that there is a $template variable being referenced and PHP is throwing the error saying $template does not exists.
This is because $template only exists inside the foreach {} block and would not be accessible from the catch {} block, this causes Magento to render a blank page or come out with an error inside the catch which is a double-fault.
The solution is to add just before the try {} block the following:
$template = "";
this should fix the issue, I already fixed it on mine and now Magento-2 is working better.
I hope this helps.
Regards
Heider