Displaying the content depending on the site language

How It Works

You can segment the content and display particular blocks only to the users viewing the page in certain languages.

Who Can Use It

Partners who have already integrated Site Builder.

How to Get It

  1. Go to Publisher Account > Site Builder.
  2. In the Header block, set up the Translations component.
  3. Select the language to hide particular blocks for.
  4. Insert the following code to the Custom code block:

<script>
  (function () {
    var blockArray = [
      {
        blockName: '.block--packs',
        blockNumber: 0
      },
      {
        blockName: '.block--description',
        blockNumber: 0
      }
    ];

    function removeBlock() {
      setTimeout(function () {
        blockArray.map(function (block) {
          return document.querySelectorAll(block.blockName)[block.blockNumber];
        })
          .forEach(function (element) {
            element && element.remove();
          });
      }, 0);
    }

    removeBlock();
  })();
</script>

  1. In the blockArray array, modify the following parameters for each block you want to hide from users for the chosen language:
    1. blockName — the name of the CSS class of the block. Possible options are:
      • .block--header (the Header block)
      • .block--hero (the Call to action block)
      • .block--html (the Custom code block)
      • .block--packs (the Packs block)
      • .block--description (the Description block)
      • .block--gallery (the Gallery block)
      • .block--requirements (the System requirements block)
      • .block--faq (the FAQ block)
      • .block--embed (the Social media widgets block)
      • .block--news (the News block)
      • .block--footer (the Footer block)
    2. blockNumber — the sequence number of the block. Minimum value is 0.
  2. Click Preview to see your changes.

Here is the tutorial video for this recipe: