Hi All,
We have a requirement wherein
1] A js file is placed in etc/clientlib folder of AEM.
2] Now, this js location is to be available on end user facing site[ or say on publish environment ] along with some user instructions text and styling with it. Basically if these are available on publish/live site , the user will be able to copy all these [location of js file say localhost:4503/etc/clientlibs/.../../sample.js , instructions text and styling ]hosted on AEM servers and use it on some other website/page.
3] Based on the environment like dev, qa.. it should pickup the domain [for which we already have backend code to read from the configuration] and link to the js file should be appropriately formed.
Any thoughts/pointers/reference code on this will be really helpful.
Solved! Go to Solution.
Views
Replies
Total Likes
Hi,
Below code works for me. It shows up in the viewsource.
<sly data-sly-test.domainvaluefromconfig ="${'http://www.sample.com'}"/>
${domainvaluefromconfig} <!--/*this prints as expected*/-->
<script type="text/javascript" src="${domainvaluefromconfig}/etc/designs/somedesign/js/script.js></script><!--/*this also has full url as expected*/-->
If you want to print it in a text area you need to do as below.
f you want to print it in a text area you need to as bw.
<textarea cols="30" rows="7">
<script type="text/javascript" src="${domainvaluefromconfig}/etc/designs/somedesign/js/script.js/><script>
</textarea>
Try sightly escape check this forum link: AEM 6.1 | Escape special chars in Sightly
You can also use StringEscapeUtils from apache commons: StringEscapeUtils (Commons Lang 2.6 API)
You can pass the html tag to wcmusepojo and get the escaped value and pass it to the textarea.
<textarea cols="30" rows="7">
${escapedhtml}
</textarea>
Views
Replies
Total Likes
Just to add.
Even if this not part of any component in cq and if there is any other way we can show this on end-user page, that would also work.
Views
Replies
Total Likes
Hi,
<script type="text/javascript" src="${domainvaluefromconfig}/etc/designs/somedesign/js/script.js></script>
Here domain value will change based on environment.
As you told that you have that config already you can read it in sightly and generate url dynamically.
Write a wcmusepojo or if you already have some code which reads config use it. Just concatenate and create the url.
Hi All,
Am getting the domain value from backend .
<sly data-sly-use.config="com.project.core.models.ConfigModel">
${configModel.endpointDomain}
</sly>
I get the correct value, say http://www.sample.com in my page.
If I try to use this data-sly-use variable in the line "<script type="text/javascript" src="${domainvaluefromconfig}/etc/designs/somedesign/js/script.js></script>", it doesn't work and nothing renders on the page.
Tried to use context uri and scriptString but didnt work.
feike_visser : Any thoughts on this will be helpful. Facing the above sightly related issue.
Views
Replies
Total Likes
Hi,
Below code works for me. It shows up in the viewsource.
<sly data-sly-test.domainvaluefromconfig ="${'http://www.sample.com'}"/>
${domainvaluefromconfig} <!--/*this prints as expected*/-->
<script type="text/javascript" src="${domainvaluefromconfig}/etc/designs/somedesign/js/script.js></script><!--/*this also has full url as expected*/-->
If you want to print it in a text area you need to do as below.
f you want to print it in a text area you need to as bw.
<textarea cols="30" rows="7">
<script type="text/javascript" src="${domainvaluefromconfig}/etc/designs/somedesign/js/script.js/><script>
</textarea>
Try sightly escape check this forum link: AEM 6.1 | Escape special chars in Sightly
You can also use StringEscapeUtils from apache commons: StringEscapeUtils (Commons Lang 2.6 API)
You can pass the html tag to wcmusepojo and get the escaped value and pass it to the textarea.
<textarea cols="30" rows="7">
${escapedhtml}
</textarea>
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies