I am getting the following error in the browser console:
knockout.js:2982 Uncaught SyntaxError: Unable to process binding "ifnot: function(){return customer().fullname }"
Message: Unable to parse bindings.
Bindings value: html:'Welcome To ________ Store'
Message: Unexpected identifier
at new Function (<anonymous>)
This occurs in a template where the $block
type is Magento\Theme\Block\Html\Header
/var/www/html/vendor/magento/module-theme/Block/Html/Header.php
content has the public function getWelcome()
/var/www/html/app/design/frontend/Sm/market/Magento_Theme/templates/html/header-style-2.phtml
returns $block
as type described above.
It calls <?php $welcomeMessage = $block->getWelcome(); ?>
at the start of the template, then later on: seems to bind here:
<span class="greet welcome" data-bind="scope: 'customer'">
<!-- ko if: customer().fullname -->
<span data-bind="text: new String('<?php echo $block->escapeHtml(__('W>
</span>
</ko -->
<!-- ko ifnot: customer().fullname -->
<span data-bind="html:'<?= $block->escapeHtml($welcomeMessage) ?>'"></>
<!-- /ko -->
</span>
I am actually not sure what is wrong, or why Knockout cannot parse the bindings. May you please assist, thanks!
Edit:
Initially (above) I just added the sections of code that I 'thought' is applicable since it is related to knockout, but full code was requested, so this makes the information long:
This spans two files: 'header.phtml' and 'header-style/header-2.phtml'
header.phtml include 'Magento_Theme::html/header-style/
. $headerStyle . '.phtml';
app/design/frontend/Sm/market/Magento_Theme/templates/html/header.phtml
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
// @codingStandardsIgnoreFile
/**
* @var \Magento\Theme\Block\Html\Header $block
*/
$_config = $this->helper('Sm\Market\Helper\Data');
$headerStyle = $_config->getThemeLayout('header_style');
include($block->getTemplateFile("Magento_Theme::html/header-style/" . $headerStyle . ".phtml"));
?>
<div style='color:red; font-size: 50%;'><p><span>Header Style Type : <?php echo $headerStyle . ".phtml (edited in : " . __FILE__ . ")" ?></span></p></div>
<?php
if ($_config->getAdvanced('show_newsletter_popup')) {
echo $block->getChildHtml('form.subscribe.popup');
}
?>
<?php if ($_config->getGeneral('menu_ontop') == 1) { ?>
<script type="text/javascript">
require([
'jquery'
], function ($) {
$window = $(window);
if ($('.header-bottom').length) {
menu_offset_top = $('.header-bottom').offset().top;
function processScroll() {
var scrollTop = $window.scrollTop();
if (scrollTop >= menu_offset_top) {
$('.header-bottom').addClass('menu-on-top');
$('body').addClass('body-on-top');
} else if (scrollTop <= menu_offset_top) {
$('.header-bottom').removeClass('menu-on-top');
$('body').removeClass('body-on-top');
}
}
processScroll();
$window.scroll(function () {
processScroll();
});
}
});
</script>
<?php } ?>
app/design/frontend/Sm/market/Magento_Theme/templates/html/header-style/header-2.phtml
<?php echo "Type of header-style : " . get_class($block); ?>
<?php $welcomeMessage = $block->getWelcome(); ?>
<div class="header-container header-style-2">
<div class="header-top">
<div class="container">
<div class="row row-topheader">
<div class="col-lg-5 col-md-3 customer-action-header">
<div class="customer-action-hd">
<span class="welcome-text">
<span class="greet welcome" data-bind="scope: 'customer'">
**<!-- ko if: customer().fullname -->
<span data-bind="text: new String('<?php echo $block->escapeHtml(__('Welcome, %1!', '%1')); ?>').replace('%1', customer().firstname)">
</span>
<!-- /ko -->
<!-- ko ifnot: customer().fullname -->
<span data-bind="html:'<?= $block->escapeHtml($welcomeMessage) ?>'"></span>
<!-- /ko -->**
</span>
<script type="text/x-magento-init">
{
"*": {
"Magento_Ui/js/core/app": {
"components": {
"customer": {
"component": "Magento_Customer/js/view/customer"
}
}
}
}
}
</script>
</span>
<?php
$login_customer = $block->getLayout()->createBlock('Magento\Customer\Block\Account\Customer');
?>
<?php if ($login_customer->customerLoggedIn()) { ?>
<a href="<?php echo $this->getUrl('customer/account/logout') ?>"
title="<?php echo __('Logout') ?>"><?php echo __('Logout') ?></a>
<?php } else { ?>
<a href="<?php echo $this->getUrl('customer/account/create') ?>"
title="<?php echo __('Create Your Account') ?>"><?php echo __('Join Free') ?></a> <?php echo __('or') ?>
<a href="<?php echo $this->getUrl('customer/account/login') ?>"
title="<?php echo __('Sign In') ?>"><?php echo __('Sign in') ?></a>
<?php } ?>
</div>
</div>
<div class="col-lg-7 col-md-9 header-top-links">
<?php echo $block->getChildHtml('currency-header'); ?>
<?php echo $block->getChildHtml('language-header'); ?>
<?php echo $block->getChildHtml('toplinks-header'); ?>
</div>
</div>
</div>
</div>
<div class="header-middle">
<div class="container">
<div class="row">
<div class="col-lg-2 logo-header">
<?php echo $block->getChildHtml('logo_theme'); ?>
</div>
<div class="col-lg-10 header-middle-right">
<div class="middle-right-content">
<div class="main-megamenu">
<?php echo $block->getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId('megamenu-horizontal')->toHtml(); ?>
</div>
<div class="minicart-header">
<div class="minicart-content">
<?php echo $block->getChildHtml('cart-header'); ?>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="header-bottom">
<div class="container">
<div class="row">
<div class="navigation-mobile-container">
<?php echo $block->getChildHtml('navigation.mobile'); ?>
</div>
<div class="col-lg-3 sidebar-megamenu">
<div class="megamenu-content-sidebar">
<div class="btn-megamenu">
<a href="javascript:void(0)"
title="<?php echo __('All Categories') ?>"><?php echo __('All Categories') ?></a>
</div>
<div class="menu-ver-content">
<?php
if ($_config->getGeneral('menu_style') == 'megamenu') {
echo $block->getChildHtml('navigation-header-megamenu');
} else {
echo $block->getChildHtml('navigation-header');
}
?>
</div>
</div>
</div>
<div class="col-lg-9 searchbox-header">
<?php echo $block->getChildHtml('search-header-pro'); ?>
</div>
</div>
</div>
</div>
</div>
escapeHtml part for if: customer().fullname
? In that sense its not 'corrupted'. I copied it from the console so it cut off, but will update with the full html content.