Search code examples
arrayssmarty

Smarty check if items in array more than 1


I use smarty to display different code and I want to check if the array of some phrase contains more than 1 items.

I want to create a if phrase, that checks if the array contains only 1 value or more. Something like this, but of course that correct.

{if $domains|@array < 1}

How can I achieve that?

The code looks like this:

$domains

Smarty_Variable Object (3)
->value = Array (3)
  0 => Array (17)
    domain => "example1.com"
    regperiod => "1"
    dnsmanagement => "on"
    emailforwarding => ""
    idprotection => ""
    addonsCount => 1
    eppvalue => ""
    fields => Array (0)
    configtoshow => true
    hosting => false
  1 => Array (17)
    domain => "example2.com"
    regperiod => "1"
    dnsmanagement => "on"
    emailforwarding => ""
    idprotection => ""
    addonsCount => 1
    eppvalue => ""
    fields => Array (0)
    configtoshow => true
    hosting => false
  2 => Array (17)
    domain => "example3.com"
    regperiod => "1"
    dnsmanagement => "on"
    emailforwarding => ""
    idprotection => ""
    addonsCount => 1
    eppvalue => ""
    fields => Array (0)
    configtoshow => true
    hosting => false
->nocache = false

Solution

  • You can use count (from the php function http://php.net/manual/es/function.count.php):

    {if $domains|@count < 1}