How to access the notification attributes via the Velocity Templates

Hristo3 years ago

Hello everybody,

Currently trying to dynamically translate the notification templates depending on the userLanguage attribute passed from the user account.

That part of the code works, but I do not know how to call the content of an attribute passed via a notification.
In this particular instance I want to pass some extra info per each notification.
Could anyone point me in the right direction please. Trying to access the value of the alarm attribute $info

#set ($api = "https://www.google.com/maps/search/?api=1&query=")
#set ($alarm = "$position.getString('alarm')")
#set ($lang = "$user.getString('userLanguage')")
#set ($info = "notification.getString('info')")

#{if}($lang == "es")
    #set ($Time = "Hora:")
    #set ($Device = "Dispositivo:")
    #set ($Alarm = "Alarma:")
    #set ($Location = "Localización:")
    #set ($Map = "Mapa:")
    #set ($viewInGoogleMaps = "Ver en Google Maps")
        #{if} ($alarm == "lowBattery")        
            #set ($alarm = "¡ALARMA! Batería baja")                
        #{else} #set ($alarm = "Another alarm")#{end}
#{else}
    #set ($Time = "Time:")
    #set ($Device = "Device:")
    #set ($Alarm = "Alarm:")
    #set ($Location = "Location:")
    #set ($Map = "Map:")
    #set ($viewInGoogleMaps = "View in Google Maps")
        #{if} ($alarm == "lowBattery")
            #set ($alarm = "ALARM! Low Battery")       
        #{else} #set ($alarm = "Another alarm")#{end}
#{end}       
    
#set ($subject = "$device.name $alarm")

<!DOCTYPE html>
<html>
<body>    
    $Time $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone) $user.getString("timezone")<br>
    $Device <strong>$device.name</strong><br>
    Imei: $device.uniqueId<br>    
    $Alarm <strong>$alarm</strong><br>        
    Info: $info
    <br>
    <br>
    $Location <a href="$webUrl?eventId=$event.id">#{if}($position.address)$position.address#{else}$position.latitude&deg;, $position.longitude&deg;#{end}</a><br>
    $Map <a href="$api$position.latitude, $position.longitude">$viewInGoogleMaps</a>
</body>
</html>
Anton Tananaev3 years ago

You can't access notification object, but you can access event object like this:

$event.getString('something')
Hristo3 years ago

Thanks Anton,
Will give it another try. Almost gave up...