📜 ⬆️ ⬇️

1C-Bitrix: correctly display the properties of the information block element

Information blocks are probably the most used module. No site on this CMS is complete without it. This is a very flexible tool, but in order to take advantage of all this flexibility, you will have to carefully study the Bitrix API. But official documentation, as we know, does not describe all the moments;)

And so, the task that stands before each developer who uses information blocks is to select the property (s) of an information block element and display it on the screen. The first half is trivial: the CIBlockElement class method is described in detail in the documentation . But with the second half (especially if a property of a complex type) is more interesting :)

Take a property like "HTML \ text". For this property, it is impossible to simply output its value (the “VALUE” key), since this is an array containing the raw values ​​and its type (html or text). No, we can, of course, format the “raw” value ourselves according to its type, but a doubt creeps into our heads - is it really not implemented in the CMS itself? How does the bitrix: news component work with arbitrary properties?
')
Actually, from the code of this very bitrix: news we will be able to find out how it works so cunningly :) But it turns out that there is 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 assumes formatting the value before output will be transformed accordingly!

Successful study of undocumented functions of the system;)

PS I have the original article.

Source: https://habr.com/ru/post/30827/


All Articles