Search code examples
templatesheaderprestashop

How can i fix Notice: Trying to access array offset on value of type null prestashop 1.7.8.8


Im working on prestashop 1.7.8.8 with theme bos nature, Im trying to fix a template issue but i cant see whats happening here. The template when i see it in front office is showing the code below:

Code:

    <div id="js-product-list-header">
        {if $listing.pagination.items_shown_from == 1}
            <div class="block-category card card-block">
                <h1 class="h1">{$category.name}</h1>
                <div class="block-category-inner">
                    {if $category.description}
                        <div id="category-description" class="text-muted">{$category.description nofilter}</div>
                    {/if}
                    {if $category.image.large.url}
                        <div class="category-cover">
                            <img src="{$category.image.large.url}" alt="
                            {if !empty($category.image.legend)}
                            {$category.image.legend}
                            {else}
                            {$category.name}
                            {/if}">
                        </div>
                    {/if}
                </div>
            </div>
        {/if}
    </div>

It says is the category-header.tpl. It throws an error like that: Notice: Trying to access array offset on value of type null

If i put the {/if} without spaces it throws me an error and if i put the { /if } like that, then shows the template code in front when im in a products category template.

Can yoou assist me with it?

Thank you in advance


Solution

  • It is probably related to this part:

    {if !empty($category.image.legend)}

    which doesn't work perfectly in Smarty. You could try:

    {if isset($category.image) && !empty($category.image.legend)} since !empty in Smarty has a faulty behavior sometimes.