
1C-Bitrix: correctly infoblock element properties
Infoblocks are probably the most used module. No site on this CMS can do without it. This is a very flexible tool, but in order to take advantage of all this flexibility, you will have to thoroughly study the Bitrix API. But the official documentation, as we know, does not describe all the points;)
And so, the task that every developer who uses information blocks faces is to select the property (s) of the information block element and display it on the screen. The first half of the case is commonplace: the methods of the CIBlockElement class are described in detail in the documentation . But with the second half (especially if the property is of a complex type) is already more interesting :)
Let's take a property like “HTML \ text”. For this property, you can’t simply display its value (the "VALUE" key), because it is an array containing raw values and its type (HTML or text). No, we can, of course, ourselves format the "raw" value according to its type, but the doubt creeps into our head - is this really not implemented in the CMS itself? How does the bitrix: news component work with arbitrary properties?
Actually, from the code of this bitrix: news itself, we can find out how it works so cleverly :) But it turns out nothing tricky! Just one call to the GetDisplayValue method of the CIBlockFormatProperties class:
And that’s it! Now in the template we can write like this:
And any property whose type involves formatting the value before output will be converted accordingly!
Successful study of undocumented system features;)
PS The original article - I have .
And so, the task that every developer who uses information blocks faces is to select the property (s) of the information block element and display it on the screen. The first half of the case is commonplace: the methods of the CIBlockElement class are described in detail in the documentation . But with the second half (especially if the property is of a complex type) is already more interesting :)
Let's take a property like “HTML \ text”. For this property, you can’t simply display its value (the "VALUE" key), because it is an array containing raw values and its type (HTML or text). No, we can, of course, ourselves format the "raw" value according to its type, but the doubt creeps into our head - is this really not implemented in the CMS itself? How does the bitrix: news component work with arbitrary properties?
Actually, from the code of this bitrix: news itself, we can find out how it works so cleverly :) But it turns out nothing tricky! Just one call to the GetDisplayValue method of the CIBlockFormatProperties class:
$ arResult ["DISPLAY_PROPERTIES"] [$ pid] =
CIBlockFormatProperties :: GetDisplayValue ($ arResult, $ prop, "news_out");
And that’s it! Now in the template we can write like this:
echo $ element ['PROPERTY_CODE'] ['DISPLAY_VALUE'];
And any property whose type involves formatting the value before output will be converted accordingly!
Successful study of undocumented system features;)
PS The original article - I have .