Search code examples
phpsmartyprestashopprestashop-1.6

Prestashop $category variable doesn't work within another if


I use Prestashop and I need to add a specific slideshow for the category->id 1 on the top of the category's products, and it's need to be within the code below:

I tried to insert this code:

{if category->id == '1'}
...
{/if}

Within this code:

{if isset($category)}
    {if $category->id AND $category->active}
        {if $scenes || $category->description || $category->id_image}
            ...
            {if $scenes}
                ...
                {include file="$tpl_dir./scenes.tpl" scenes=$scenes}
                {if $category->description}
                    ...
                    {if Tools::strlen($category->description) > 350}
                        ...
                    {else}
                        {$category->description}
                    {/if}
                    ...
                {/if}
                ...
            {else}
                THERE'S WHERE I TRIED INSERT THE CODE
            {/if}
        {/if}
    {/if}
{/if}

And it doesn't work.. why?

Regards,


Solution

  • Because you have placed in wrong position :)

    {if isset($category)}
        {if $category->id AND $category->active}
            {if $scenes || $category->description || $category->id_image}
                ...
                {if $scenes}
                    ...
                    {include file="$tpl_dir./scenes.tpl" scenes=$scenes}
                    {if $category->description}
                        ...
                        {if Tools::strlen($category->description) > 350}
                            ...
                        {else}
                            {$category->description}
                        {/if}
                        ...
                    {/if}
                    ...
                {else}
                    THERE'S WHERE I TRIED INSERT THE CODE (WRONG)
                {/if}
            {/if}
            THERE'S WHERE YOU HAVE TO PLACE THE CODE
            {if $category->id eq 1}
                /* some stuff */
            {/if}
        {/if}
    {/if}
    

    For the next time fix the indentation and you reach the goal by yourself ;)