Using Placeholders

In most websites, there are strings or variables that will be used throughout the site. Especially in sites that need to support multiple languages, it is not a good idea to hard code such values. Instead placeholders can be used and managed centrally.

For information how to author placeholders, see the placeholders documentation in the publish section.

You can import fetchPlaceholders in your block’s JS or scripts.js and use it as follows to retrieve placeholder strings. You probably have some function or logic in your project to determine the language of the current page based on its path or metadata. In this example, we’ll simply hardcode it to en. This means it will fetch a placeholders sheet in the en folder. Omitting the argument will assume there’s a placeholders sheet in the root folder.

https://gist.github.com/rofe/b4cfd6269f02742ce6acf4a8822fa2b3

Key formatting

Keys which contain spaces or dashes in the placeholder sheet will be camel-cased for easier access in JavaScript:

You can use the helper function toCamelCase to convert keys to property names.