Forum Discussion

lilim's avatar
lilim
Boss
9 years ago

Add category name to email template

In the General Subscription Notification email template, I am attempting to add the category name after the board title. According to this article: Email template context object, coreNode.title seemed like the object to use, since board is its own object and I want to know the node the board exists in.

 

See the change I made in red text below:

 

${notification.message.localizedObjectType} in 
${notification.message.board.title} : ${coreNode.title}
on ${notification.formattedDateForMessageEdit}
in the ${community.title} ${eventDetails}:

However, this just spits out some random board when testing.

 

 

I also tried <span class="node-name">${coreNode.title}</span> as seen used in the default Unanswered Thread email template, but this had the same result.

 

Edit: I just tested the Unanswered Thread email template, and it also showed me a random board name.

 

So perhaps coreNode.title isn't the correct object to use for category and/or there's another way to insert it into the email template.

 

Any help is appreciated. Thanks!

 

4 Replies

  • Hi lilim,

     

    what does "testing" in your case mean? If you use the send a test email from the template editor view in studio, you will always get a random board for the ${coreNode.title} context object. I think this happens while the studio does not have any context, like boards, categories etc. Usually the "trigger" of the mail is a board object which has a board context.

     

    Using the coreNode object for your use case seems not correct, because the coreNode object is always replaced with current active node. For example if you working on board level (e.g. on board "LabVIEW Add-Ons") the ${coreNode.title} object will return "LabVIEW Add-Ons".

     

    Maybe you could use something like

     

    ${coreNode.ancestors}

    to show the parent of the board in your mail template. Check the freemarker context objects for more information.

     

    I'm not sure if the ancestors property could be used within mail templates.

     

    Regards,

    Christian

  • lilim's avatar
    lilim
    Boss
    9 years ago

    Thanks for the reply, Christian. Yes, I was testing by sending the test email to myself from Studio. I see now what you are saying -- I'm always returning the most recently active board when doing this test. Email notifications from stage aren't working anymore, otherwise I could test this properly. It's possible that ${coreNode.title} is correct when the email template has some context to work with.

     

    I did try adding ${coreNode.ancestors} to the template, and the result returned:

     

    [lithium.eval.velocity.CoreNodeTemplateModel@a54cc6b8, 
    lithium.eval.velocity.CoreNodeTemplateModel@e490cafc,
    lithium.eval.velocity.CoreNodeTemplateModel@76850eb6]

    :catsurprised:

    I assume this occurred because that's a FreeMarker context object, and only Velocity context objects should be used in email templates.

     

    Thanks,

    Lili

     

     

  • ClaudiusH's avatar
    ClaudiusH
    Khoros Alumni (Retired)
    8 years ago

    I haven't found a good way to obtain the category/categories for a content pice so far. The closest that takes you there is indeed tracing along the ancestors and checking the node type for each of the ancestor: https://community.lithium.com/t5/Developers-Discussion/Get-ID-of-current-category/m-p/125151

    Which does not work too well in the email template Velocity environment :(

     

    ${notification.message}

    might return a message context object like documented in https://freemarker-docs-portal.lithium.com/refer/contextObjects#message but even that won't bring you far in obtaining the category.

     

    Maybe you can work around by hiding the category in some short / long description field of the board (depending on whether you not surface this description somewhere in your community UI)?

  • lilim's avatar
    lilim
    Boss
    8 years ago

    The category description is an interesting idea, but we do display these elsewhere in the community. I also didn't see a context object for it. :catsad: