0

I am trying to get a page property in the head of my page basically to make it universally available so that the front end developers can use it in their scripts as they will.

This is on AEM 6.3. And I've already tried to include a script in the head.html but it can't read the page properties in a script tag.

<script>
    window.myAppEndpoint = {
        baseURL: "${properties.myappendpoint}"
    };
</script>

I expect the window object to populate with my endpoint value be able to use it anywhere in the application.

Jens
  • 20,533
  • 11
  • 60
  • 86
Vishal--JAVA--CQ
  • 188
  • 1
  • 2
  • 18

2 Answers2

0

You should be able to do this provided:

  1. The myappendpoint property is defined for the page jcr:content node
  2. You are using the proper display context: baseURL: "${properties.myappendpoint @ context='uri'}"
Vlad
  • 10,602
  • 2
  • 36
  • 38
  • This saved my day. But I want to know why the property value was not set until I declared a context? – Vishal--JAVA--CQ May 28 '19 at 13:41
  • @Vishal--JAVA--CQ , because context is mandatory inside script tags, see https://github.com/adobe/htl-spec/blob/master/SPECIFICATION.md#113-context-sensitive – Vlad May 30 '19 at 03:45
0

You can create a global object in js and include that js in the clientlib at the template level. Or use the global objects available in HTL. Please have a look here.

Sadistic
  • 541
  • 4
  • 12