Персональный блог
В новых версиях k2, чтобы выводить доп. поле отдельно от массива ни нужно ни каких костылей, тут как говорить все уже сделано за вас.
<?php if ($this->item->params->get('itemExtraFields') && isset($this->item->extraFields->my_field) && !empty($this->item->extraFields->my_field->value)): ?>
<?php echo $this->item->extraFields->my_field->name; ?>:
<?php echo $this->item->extraFields->my_field->value; ?>
<?php endif; ?>
<?php if ($this->item->params->get('catItemExtraFields') && isset($this->item->extraFields->my_field) && !empty($this->item->extraFields->my_field->value)): ?>
<?php echo $this->item->extraFields->my_field->name; ?>:
<?php echo $this->item->extraFields->my_field->value; ?>
<?php endif; ?>
<?php if ($item->params->get('tagItemExtraFields',0) && isset($item->extraFields->my_field) && !empty($item->extraFields->my_field->value)): ?>
<?php echo $item->extraFields->my_field->name; ?>:
<?php echo $item->extraFields->my_field->value; ?>
<?php endif; ?>
Чтобы выводить доп. поле отдельно от массива, на нужно получать конкретный объект из массива по ключу. А чтобы ключи были заранее известны, наиболее верным вариантом будет преображать массив, заменив обычные ключи на алиас полей, не забыв при этом исключить из массива старые объект. Либо же собрать новый массив с нужными нам полями.
<?php
if($this->item->params->get('itemExtraFields') && count($this->item->extra_fields)) {
foreach ($this->item->extra_fields as $key => $field) {
$this->item->extra_fields[$field->alias] = $field; // Add field with new key
unset($this->item->extra_fields[$key]); // delete field with with old key
}
}
?>
<?php if ($this->item->params->get('itemExtraFields') && count($this->item->extra_fields) && isset($this->item->extra_fields['my_field']) && !empty($this->item->extra_fields['my_field']->value)): ?>
<?php echo $this->item->extra_fields['my_field']->name; ?>:
<?php echo $this->item->extra_fields['my_field']->value; ?>
<?php endif; ?>
<?php
if($this->item->params->get('itemExtraFields') && count($this->item->extra_fields)) {
foreach ($this->item->extra_fields as $key => $field) {
$this->item->extra_fields[$field->alias] = $field; // Add field with new key
unset($this->item->extra_fields[$key]); // delete field with with old key
}
}
?>
<?php if ($this->item->params->get('catItemExtraFields') && count($this->item->extra_fields) && isset($this->item->extra_fields['my_field']) && !empty($this->item->extra_fields['my_field']->value)): ?>
<?php echo $this->item->extra_fields['my_field']->name; ?>:
<?php echo $this->item->extra_fields['my_field']->value; ?>
<?php endif; ?>
<?php
if($item->params->get('tagItemExtraFields',0) && count($item->extra_fields)) {
foreach ($item->extra_fields as $key => $field) {
$item->extra_fields[$field->alias] = $field; // Add field with new key
unset($item->extra_fields[$key]); // delete field with with old key
}
}
?>
<?php if ($item->params->get('tagItemExtraFields',0) && count($item->extra_fields) && isset($item->extra_fields['my_field']) && !empty($item->extra_fields['my_field']->value)): ?>
<?php echo $item->extra_fields['my_field']->name; ?>:
<?php echo $item->extra_fields['my_field']->value; ?>
<?php endif; ?>
<?php
if($this->item->params->get('itemExtraFields') && count($this->item->extra_fields)) {
$myFields = array('my_field','my_field2'); // Need fields 'field_alis'
$this->item->my_extra_fields = array();
foreach ($this->item->extra_fields as $key => $field) {
if (in_array($field->alias, $myFields)) {
$this->item->my_extra_fields[$field->alias] = $field; // Add field with new key
unset($this->item->extra_fields[$key]); // delete field with with old key
}
}
}
?>
<?php if ($this->item->params->get('itemExtraFields') && count($this->item->extra_fields) && isset($this->item->my_extra_fields['my_field']) && !empty($this->item->my_extra_fields['my_field']->value)): ?>
<?php echo $this->item->my_extra_fields['my_field']->name; ?>:
<?php echo $this->item->my_extra_fields['my_field']->value; ?>
<?php endif; ?>
<?php
if($this->item->params->get('catItemExtraFields') && count($this->item->extra_fields)) {
$myFields = array('my_field','my_field2'); // Need fields 'field_alis'
$this->item->my_extra_fields = array();
foreach ($this->item->extra_fields as $key => $field) {
if (in_array($field->alias, $myFields)) {
$this->item->my_extra_fields[$field->alias] = $field; // Add field with new key
unset($this->item->extra_fields[$key]); // delete field with with old key
}
}
}
?>
<?php if ($this->item->params->get('catItemExtraFields') && count($this->item->extra_fields) && isset($this->item->my_extra_fields['my_field']) && !empty($this->item->my_extra_fields['my_field']->value)): ?>
<?php echo $this->item->my_extra_fields['my_field']->name; ?>:
<?php echo $this->item->my_extra_fields['my_field']->value; ?>
<?php endif; ?>
<?php
if($item->params->get('tagItemExtraFields',0) && count($item->extra_fields)) {
$myFields = array('my_field','my_field2'); // Need fields 'field_alis'
$item->my_extra_fields = array();
foreach ($item->extra_fields as $key => $field) {
if (in_array($field->alias, $myFields)) {
$item->extra_fields[$field->alias] = $field; // Add field with new key
unset($item->my_extra_fields[$key]); // delete field with with old key
}
}
}
?>
<?php if ($item->params->get('tagItemExtraFields',0) && count($item->extra_fields) && isset($item->my_extra_fields['my_field']) && !empty($item->my_extra_fields['my_field']->value)): ?>
<?php echo $item->my_extra_fields['my_field']->name; ?>:
<?php echo $item->my_extra_fields['my_field']->value; ?>
<?php endif; ?>