How can I check the name of an item for foreach and display it?
My currenty code is, which checks if the item is even or odd:
{foreach $panels as $item}
{if $item@iteration is odd}
{outputHomePanels}
{/if}
{/foreach}
Entire code:
{function name=outputHomePanels}
<div menuItemName="{$item->getName()}" class="panel panel-default panel-accent-{$item->getExtra('color')}{if $item->getClass()} {$item->getClass()}{/if} {$item->getName()}"{if $item->getAttribute('id')} id="{$item->getAttribute('id')}"{/if}>
<div class="panel-heading">
<h3 class="panel-title">
{if $item->getExtra('btn-link') && $item->getExtra('btn-text')}
<div class="pull-right">
<a href="{$item->getExtra('btn-link')}" class="more-link">
{$item->getExtra('btn-text')}
</a>
</div>
{/if}
<div class="clientarea-icon {$item->getName()}">
{if $item->hasIcon()}<i class="{$item->getIcon()}"></i>{/if}
</div>
<div class="clientarea-title">
{$item->getLabel()}
</div>
{if $item->hasBadge()}<span class="badge">{$item->getBadge()}</span>{/if}
</h3>
</div>
{if $item->hasBodyHtml()}
<div class="panel-body">
{$item->getBodyHtml()}
</div>
{/if}
{if $item->hasChildren()}
<div class="list-group{if $item->getChildrenAttribute('class')} {$item->getChildrenAttribute('class')}{/if}">
{foreach $item->getChildren() as $childItem}
{if $childItem->getUri()}
<a menuItemName="{$childItem->getName()}" href="{$childItem->getUri()}" class="list-group-item{if $childItem->getClass()} {$childItem->getClass()}{/if}{if $childItem->isCurrent()} active{/if}"{if $childItem->getAttribute('dataToggleTab')} data-toggle="tab"{/if}{if $childItem->getAttribute('target')} target="{$childItem->getAttribute('target')}"{/if} id="{$childItem->getId()}">
<div class="clientarea-icon {$childItem->getLabel()|stristr:'<' : true}">
<i class="icon-clientarea-product"></i>
</div>
<div class="clientarea-title">
{assign var="splitItem" value=" - "|explode:$childItem->getLabel()}
{$splitItem[1]}
</div>
{if $childItem->hasBadge()} <span class="badge">{$childItem->getBadge()}</span>{/if}
</a>
{else}
<div menuItemName="{$childItem->getName()}" class="list-group-item{if $childItem->getClass()} {$childItem->getClass()}{/if}" id="{$childItem->getId()}">
{if $childItem->hasIcon()}<i class="{$childItem->getIcon()}"></i> {/if}
{$childItem->getLabel()}
{if $childItem->hasBadge()} <span class="badge">{$childItem->getBadge()}</span>{/if}
</div>
{/if}
{/foreach}
</div>
{/if}
</div>
{/function}
I need to check if the name of the item is "Active Products/Services".
How can I achieve that?
if ( $item == "Active Products/Services" ) {
// code here
}
This looks like Smarty code, not PHP code. Also your semantics are somewhat confusing. If you mean how should you check for a match on the key value of the array, then....
{foreach $panels as $name=>$item}
{if ( "Active Products/Services" == $name ) }
...
{/if}
{if $item@iteration is odd}
{outputHomePanels}
{/if}
{/foreach}
OTOH, if you only want to "outputHomePanels" where the name is "Active Products/Services" then...
{ if ($name = isset($item['Active Products/Services']) ? $item['Active Products/Services'] : false ) }
{outputHomePanels}
{/if}
...but you shouldn't be implementing application logic in smarty - this should be in PHP.