How to display content depending on site language
How it works
You can segment the content and display particular blocks only to the users viewing the page in certain languages via a custom HTML code. You may use an existing solution or add your own code.
How to get it
Using an existing solution
- Open your project in Publisher Account.
- In the side bar click Site Builder.
- Click Open Site Builder.
- In the Header block, set up the Translations component.
- Select the language to hide particular blocks for.
- Insert the following code to the Custom code block:
Copy
- html
<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>
- In the
blockArray
array, modify the following parameters for each block you want to hide from users for the chosen language: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 FAQs block)
- .block--embed (the Social media widgets block)
- .block--news (the News block)
- .block--footer (the Footer block)
blockNumber
— the sequence number of the block. Minimum value is0
.
- Click Preview to see your changes.
Watch the tutorial video for this instruction:
Adding your own code
- In the Builder, click Add block and choose Custom code.
- Insert your own code to the block.
Was this article helpful?
Thank you for your feedback!
We’ll review your message and use it to help us improve your experience.Useful links
Last updated: March 26, 2024Found a typo or other text error? Select the text and press Ctrl+Enter.