Monday , February 3 2025

How to display a product property in Bitrix only for a specific user group

By default, the properties are displayed, for example, in this file /bitrix/templates/template/components/bitrix/news.detail/catalog/template.php like this:

<?if($arResult["PROPERTIES"]["test123"]["VALUE"]):?>
   <div class="project-top__parameter-item">
      <div class="project-top__parameter-name">
         <?=$arResult["PROPERTIES"]["test123"]["NAME"]?>
      </div>
      <div class="project-top__parameter-line"></div>
         <div class="project-top__parameter-size">
         <?=$arResult["PROPERTIES"]["test123"]["VALUE"]?> 
      </div>
   </div>
<?endif;?>

where test123 is a product property. If you need to hide this property for all groups, for example, except for Admins (1) and Content Managers (5), then the entire construction above needs to be wrapped in:

<?if (CSite::InGroup(array(1,5))):?>
<?endif;?>

As a result, the property should look like this:

<?if (CSite::InGroup(array(1,5))):?>
<?if($arResult["PROPERTIES"]["test123"]["VALUE"]):?>
   <div class="project-top__parameter-item">
      <div class="project-top__parameter-name">
         <?=$arResult["PROPERTIES"]["test123"]["NAME"]?>
      </div>
      <div class="project-top__parameter-line"></div>
         <div class="project-top__parameter-size">
         <?=$arResult["PROPERTIES"]["test123"]["VALUE"]?> 
      </div>
   </div>
<?endif;?>
<?endif;?>

About iryna

I'm Iryna, a web developer from Ukraine with a decade of experience solving complex technical challenges in the world of freelance. Throughout my career, I've worked on everything from troubleshooting server-side issues and optimizing website performance to enhancing user interfaces. On this blog, I share detailed solutions to the technical problems I’ve encountered and methods that have worked best for me. In addition to my technical expertise, I’m also passionate about digital drawing. I hope the tutorials and insights I provide here will help both fellow developers and creatives alike in their own projects.

Check Also

Include the file and display the value if it is specified in this file

This method was created for SEO edits on the Bitrix site (generated h1 values were …

Leave a Reply

Your email address will not be published. Required fields are marked *