E
E
Ekaterina2022-03-21 15:18:33
1C-Bitrix
Ekaterina, 2022-03-21 15:18:33

How to set a css class for a certain property of a product?

There is a product property with the symbolic code "PROP_INCOME" and it is necessary to set a certain css-style for it, for example - font-weight: 600;
How to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2022-03-21
@Ekaterina002

`$value = value.style.font-weight == '600';` - what programming language?! :) Is it some mix of php+javascript (although the spelling is not correct then)? ... it won't work.
You need to find a piece of code in the component template code where the product properties are displayed. And there already check / search for the desired property, and when you find it, then substitute either the inline font-weight style or even better the style class. do not forget to add the style class itself to style.css
For example, if the code you provided is cut from the correct place from the component template, then in the end it will turn out something like this:

<?php
foreach ($arResult['PROPERTIES'] as $code => $value) {
    if (in_array ($code, ELEMENT_PROPERTIES_SKIP) || empty($value['VALUE']))
    {
        continue;
    }                
    
    $class = $style = '';
    if ($code == 'PROP_INCOME') {
        $class = 'fb-600';
        $style = 'style="font-weight: 600;"';
    }
    ?>
        <div class="catalog-property <?=$class?>">
            <?=$value?>
        </div>

        or

        <div <?=($style??'')?>>
            <?=$value?>
        </div>
    <?php
} 
?>

The class/style for a property can (and sometimes needs to) be prepared not in the template, but in the result_modifier.php file so that the template has as little logic as possible, only output. Depending on the customized component or the standard Bitrix component, there may be some changes, also your properties should "reach" the component and the template, which may require the settings of the infoblock / component to be viewed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question