Hi,
For tracking purpose on different page , I need to display page properties( page title, tags, publication date) in source code of the page through javascript function.
My Client wants to add one javascript function on parent page and add variables for all three page propertie.By USE api I can handle this but how can i display the page properties by javascript in source code .
Something like this:
<script>
function tackingData() {
title: "Abc home page",
tags: "abcpagetag",
publisheddate: "2018-04-30T14:02:56.421Z"
}
</script>
Please suggest.
Regards,
Solved! Go to Solution.
Views
Replies
Total Likes
You can use the properties object directly in the script
<script>
function tackingData() {
title: "${properties.propertyname}",
tags: "${properties.propertyname}",
publisheddate: "${properties.propertyname}"
}
</script>
and put this in any html and make a data-sly-include of that html in head.html of page component.
Views
Replies
Total Likes
You can use the properties object directly in the script
<script>
function tackingData() {
title: "${properties.propertyname}",
tags: "${properties.propertyname}",
publisheddate: "${properties.propertyname}"
}
</script>
and put this in any html and make a data-sly-include of that html in head.html of page component.
Views
Replies
Total Likes
Hi,
No need to write Use API,
you can put below snippet in your page component,
<script>
function trackingData() {
var jsonData = { "title": "${pageProperties.jcr:title @ context='scriptToken'}",
"tags": "${pageProperties.cq:tags @ context='unsafe'}",
"publisheddate": "${'MM/dd/yyyy HH:mma' @ format=pageProperties.cq:lastReplicated, context='unsafe'}"
}
return jsonData;
}
</script>
Thanks
Arun
Views
Replies
Total Likes
Great Answer. That is the correct answer - you can access any component prop using HTL syntax as shown above.
Views
Replies
Total Likes
thank you so much , its working fine.
Regards,
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies