Skip to content

Placeholders

Suppenhuhn79 edited this page May 17, 2021 · 2 revisions

Text and non-ps attributes within a snippet may contain placeholders. These will be replaced by values on production.

Placeholders are enclosed in double curly brackets (e.g. {{my-value}}).

Example:

Snippet:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<ps:pagesnippets xmlns:ps="https://github.com/suppenhuhn79/pagesnippets">
  <ps:snippet name="customer">
    <div class="customer" data-cusnumber="{{customer.number}}">
      <div>{{customer.name.salutation}} {{customer.name.last-name}}</div>
    </div>
  </ps:snippet>
</ps:pagesnippets>

Script:

var data = {
  "customer": {
    "number": 12345,
    "name": {
      "salutation": "Mr.",
      "first-name": "Bob",
      "last-name": "Miller"
    }
  }
};
document.body.appendChild(pageSnippets.customer.produce(this, data));

Results in:

<div class="customer" data-cusnumber="12345">
  <div>Mr. Miller</div>
</div>
Clone this wiki locally