Jump to content

Smarty shorter if statement - get rid of repeatability


hakeryk2

Recommended Posts

Hello,

 

Does anynone know how to write it down in a shorter way? Tu put those ID into arrays or something?

{if
$product->id|intval == 1478
OR $product->id|intval == 2063
OR $product->id|intval == 3608
OR $product->id|intval == 3511
OR $product->id|intval == 5644
OR $product->id|intval == 5655
OR $product->id|intval == 5656
OR $product->id|intval == 5665
OR $product->id|intval == 5678
}  {/if}

or this example

{if
    in_array(140,Product::getProductCategories($product->id|intval))
    OR in_array(33,Product::getProductCategories($product->id|intval))
    OR in_array(34,Product::getProductCategories($product->id|intval))
    OR in_array(35,Product::getProductCategories($product->id|intval))
}

Thank You.

Link to comment
Share on other sites

Kind a weird because this works

{assign var=productListPromotion value=array(5764, 1478, 2063, 3608, 3511, 5644, 5655, 5656, 5665, 5678, 1935, 3610, 5700, 2253, 2253, 2410, 2411, 2412, 2414, 2416, 2419, 2419, 969, 1547, 5328, 1962, 1972, 1351, 1352, 1352, 3393, 3393, 6155, 6156, 6157, 6158, 6159, 6160, 6161, 6162, 6163, 6164, 6165, 6166, 6142, 6142, 6146, 6144, 1449, 6179, 6181, 6147, 6151, 6150, 6148, 6152)}
{if in_array($product->id|intval, $productListPromotion)}
<div class="row">It works!</div>
{/if}

which is pretty much almost same thing and Your example is not working in my case.

 

P.S If someone will look for to check array in array this example will be good:

{assign var=myArray2 value=array(5, 99, 22)}
{if  array_intersect($myArray2, $myAnotherArray)}
  code goes here
{/if}
Edited by hakeryk2 (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...