Giorgi625 VIP
Total posts: 655
27 Май 2017 13:25

I use custom template and this is how I add field in template file:

<?php if(isset($item->fields_by_key[$params->get('tmpl_params.field_othertitles')])): ?>
    <div class="field-othertitles">
        <?php echo $item->fields_by_key[$params->get('tmpl_params.field_othertitles')]->result; ?>
    </div>
<?php endif; ?>

I have 12 fields added using same type of code. How can I add label to each field so that it will look at field parameter if label needs to be shown or not and breakable or not.


<?php if($field->params->get('core.show_lable') > 1):?> <label id="<?php echo $field->id;?>-lbl"> <?php echo $field->label; ?> </label> <?php if($field->params->get('core.label_break') > 1):?> <?php endif;?> <?php endif;?>

this code is from default tempalte but it does not work because I am using key-s to display fields how I guess. What I need to edit in this code? I was not able to find info in documentation.

Последние изменения: 02 Июнь 2017


Sergey
Total posts: 13,748
02 Июнь 2017 12:32

In general, when you place a field in template you already know what field it is. So you can tipe label directly.

<?php echo 'My Label: '.$item->fields_by_key[$params->get('tmpl_params.field_othertitles')]->result; ?>

but if you want to use same technique as in default template and you create universal template that is configurable and work with other types too then

<?php if($item->fields_by_key[$params->get('tmpl_params.field_othertitles')]->params->get('core.show_lable') > 1):?>
    <label id="<?php echo $field->id;?>-lbl">
        <?php echo $item->fields_by_key[$params->get('tmpl_params.field_othertitles')]->label; ?>
    </label>
    <?php if($item->fields_by_key[$params->get('tmpl_params.field_othertitles')]->params->get('core.label_break') > 1):?>
    <?php endif;?>
<?php endif;?>

Giorgi625 VIP
Total posts: 655
02 Июнь 2017 18:04

Sergey In general, when you place a field in template you already know what field it is. So you can tipe label directly.

but if you want to use same technique as in default template and you create universal template that is configurable and work with other types too then

Yes I use one template in many types so second option is a solution for me.

Thanks

Работает на Cobalt