Friday , December 20 2024

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 admin

Hi there! My name is Iryna, I am a web developer from Ukraine. While working on freelance projects I often face different technical issues and in this blog I publish articles on how to solve them. I am also interested in digital drawing and in this blog you will find brief tutorials that helped me and hopefully can help you as well.

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 *