ADOBE EXPERIENCE MANAGER (AEM)

AEM JavaScript Use-API String Multi JSON

JSON content parsing, e.g., jcr:content Type string[] with JSON values.

CRXDE Properties editor showing expanded String[] Multi value JSON
JCR Properties - String[] Multi JSON values

Use-API JavaScript

myProp.js
"use strict";

use(function() {

  let val = [];

  try {
     let myPropStrings = properties.get('myProp') || [];
     val = myPropStrings.map(function(data){
         return JSON.parse(data);
     });
  } catch (e) {
      log.error('Could not read myProp: ' + e.message);
  }

  return val;

});

HTL Sample

<div data-sly-use.data="myProp.js">
  <sly data-sly-list="${data}">
    <h3 data-label="${item.label}">
      ${item.title}
    </h3>
    <div>${item.desc}</div>
  </sly>
</div>

Part 3 of 4 in the AEM JavaScript Use-API series.

Part 1 | AEM JavaScript Use-API ResourceUtils | Stubbing Data with AEM JavaScript Use-API

comments powered by Disqus