Perficient AEM 知识点 Feb/11

本文深入探讨了HTL与JavaScript在Adobe Experience Manager(AEM)平台上的运用,包括HTL语法中获取父节点路径、使用三目运算符、DOM操作,以及原生JS实现图片轮播和按钮控制图片切换等功能。同时,文章提供了将AEM_JSON字符串转换为JSON对象的方法,并展示了如何处理多文件上传的JSON数据。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

currentNode.Parent.pathHTL 获取当前节点的父节点路径
${varChoice ? var1 : var2}三目运算符
document.getElementById(“id”)通过Id获取DOM节点
sly data-sly-repeat.item循环迭代–可以是content的Json/也可以是注入的Java
<input type=“hidden” id=“str1” value=""给input一个Id并隐藏起来,JS就可以取到值
  • 如何获取fileupload通过url上传的图片,图片以二进制形式存在content节点下
  • Javascript实现轮播图片

原生JS实现点击按钮切换图片

<img border="0" alt="XXX" src="C:\Users\Public\Pictures\Sample Pictures\2018-lids-hero-new-lg.jpg" id="bbb"/>
<input type="button" value="点击切换" onclick="changeImg();"/>

<script>
	function changeImg() {
	    var obj = document.getElementById("bbb");   
		//alert(obj.getAttribute("src"));
	    if (obj.getAttribute("src") == "C:\\Users\\Public\\Pictures\\Sample Pictures\\2018-lids-hero-new-lg.jpg") {
	        obj.setAttribute("src", "C:\\Users\\Public\\Pictures\\Sample Pictures\\hero-pd-banners-4.jpg");     
	    } else { 
	        obj.setAttribute("src", "C:\\Users\\Public\\Pictures\\Sample Pictures\\2018-lids-hero-new-lg.jpg"); 
	    }
</script>
obj.getAttribute(“src”)得到对象的src
C:\Users\Public\Pictures\Sample Pictures\路径要加两个反斜杠转义

原生JS将AEM_JSON字符串转为JSON对象

  • 从multiFiledq取到的JSON字符串如下
    {
    “hero_name”: “Perficient Trusted to Deliver DPA”,
    “hero_picture”: “/content/dam/PeficientDigit/hero-insights-lg.jpg”,
    “hero_tip”: “Named a “Strong Performer” in the Forrester Wave”,
    “hero_button_text”: “See Why”,
    “hero_button_url”: “https://www.baidu.com/
    },
    {
    “hero_name”: “Your Brand is Made of Moments”,
    “hero_picture”: “/content/dam/PeficientDigit/hero-pd-banners-4.jpg”,
    “hero_tip”: “Because great brands are the sum of every great customer moment.”,
    “hero_button_text”: “Learn More About Perficient Digital”,
    “hero_button_url”: “https://www.perficientdigital.com/
    }

  • HTL代码

<input type="hidden" id="str1" value=${properties.hero_block} />

<script>
    var json_txt=document.getElementById("str1").value;
	var str_obj="{ \"hero_block\" : [" +json_txt+ "]}";
	console.log(str_obj);

	var obj = eval ("(" + str_obj + ")");
    console.log(json_txt);
    alert(obj.hero_block[0].hero_name);
</script>
var str_obj="{ “hero_block” : [" +json_txt+ “]}”;字符串还要+对象名才能变成JSON对象
符串内部既包含’又包含"用转义字符\来标识
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值