Search code examples
phphtmlsmarty

Harmonize If statement with one condition and multiple values


I have this code written to exempt breadcrumb from certain Prestashop 1.7 pages and it works. However, the way the condition - $page.page_name - is repeated does not appear okay with me especially if I intend to exempt the breadcrumbs from additional web pages. Currently, the index and order-confirmation pages are exempted and I would be adding more.

{if $page.page_name != 'index' && $page.page_name != 'order-confirmation'}
                                {include file='_partials/breadcrumb.tpl'}
                            {/if}

Please suggest if there is a better and more precise way to write this code. I tried the code below but it didn't work:

{if $page.page_name != 'index, order-confirmation'}
                                {include file='_partials/breadcrumb.tpl'}
                            {/if}

Solution

  • you can use something like this:

    {if !in_array($page.page_name, array('index','order-confirmation'), true) }
        {include file='_partials/breadcrumb.tpl'}
    {/if}