How can I display image in velocity template

血红的双手。 提交于 2021-02-10 06:59:40

问题


How can I display this image in velocity template? Is there any configuration required to display image? I have java configuration for velocity. Please help me. Thanks in advance.


回答1:


Thank you very much for your kind reply glw, issue already fixed. I forgot that email template takes only live images path which are deployed, not local project paths like src="${pageContext.request.contextPath}/resources/images/.jpg" Issue is fixed by src="www..com/images/.jpg".




回答2:


I'm using base 64 image to populate data, the code for template is

<!DOCTYPE html>
<html>
<body style="margin:0;">
<table width="100%" cellpadding="0" cellspacing="0" border="0" align="center" style="max-width: 640px; border: 1px solid #dfdfdf; font-family:'Helvetica Neue', Helvetica, Arial, sans-serif; letter-spacing: 0.5px; color: #404040;">
    <tr>
        <td valign="top" style="padding: 30px 20px 20px;">
            <table width="100%" cellpadding="0" cellspacing="0" bgcolor="#fff" style="border-collapse:collapse;border:1px solid #808080;">
            
                <tr>
                    <td align="left" valign="top" style="padding: 10px; border: 1px solid #808080; color: #808080;">Address</td>
                    <td align="right" valign="top" style="padding: 10px; border: 1px solid #808080; color: #404040; font-weight: bold;">${address}</td>
                </tr>
                <tr>
                    <td align="left" valign="top" style="padding: 10px; border: 1px solid #808080; color: #404040; font-weight: bold;">Aadharphoto</td>
                    <td align="right" valign="top" style="padding: 10px; border: 1px solid #808080; color: #404040; font-weight: bold;">
                    <img  src = 'data:image/png;base64,${photo}' alt="Aadharphoto" style="width:300px"/>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
</table>
</body>

</html>

code to populate template

Map<String, String> templatedata = eData(response); 
/*Map<String, String> templatedata = new HashMap<>();
 templatedata.put("address", response.getAddress());
 templatedata.put("photo", response.getBase64Photo()); //iVBORw0KGgoAAAANSUhEUgAAAAUA
    AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
        9TXL0Y4OHwAAAABJRU5ErkJggg==
[![enter image description here][1]][1]*/

 public String createContent(EmailTemplate template, Map<String, String> data) {
 return VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, template.getFileName(), objectMap);
}

output image : https://i.stack.imgur.com/wvloX.png



来源:https://stackoverflow.com/questions/42489968/how-can-i-display-image-in-velocity-template

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!