Freemarker If/else not working, strange.
I am not able to handle the exception here
Below is the response XML which is giving the error:
<response status="error"> <error code="503"> <message>An object in the path is null.</message> </error> </response>
I check the status of the response from the status attribute and if the status is equals to succes, i pass the returned value, else a default value.
But the issue is, it is not working. Below is my FTL code for the same. The error block doesn't return anything. Why?
<#assign check_status = rest("/users/id/${user.id}/profiles/avatar/size/profile")>
<#assign user_avatar = rest("/users/id/${user.id}/profiles/avatar/size/profile").image> <#if check_status.@status = "success"> SUCCESS: ${check_status.@status} <#else> ERROR: ${check_status.@status} </#if>
I'm a little late to the party, but thought I'd share a work-around I've used in the past for this situation. In the code below, I check first to see whether the user has an avatar. I do this by seeing if the object returned via the REST API is not null. If it's not null (there's an image), then I make an additional REST API call to get the avatar in the desired size.
<#attempt> <#assign avatarObj = restadmin("/users/id/${user.id?c}/profiles/avatar").image /> <#if !((avatarObj.@null[0])?? && avatarObj.@null=="true") > <#assign avatar = restadmin("/users/id/${user.id?c}/profiles/avatar/size/profile").image /> </#if> <#recover> </#attempt> ${avatar.url!""}
I hope this helps!