4 Results
Unsolvable error trying to get tags for a message
...t;/#list> <#else> <#assign utag = "NONE" /> </#if> I want it to plug into the JSON-LD code as the keywords for the message (as defined by the user): <s...Solved430Views
Sign in to react to this post4Comments
- luk7 years agoBoss
It would be helpful if you could post the actual freemarker error that you're getting, there is usually some information that can point in the direction of the problem. So I'm trying to "blindly" debug your issue =D...
let's see, for example this part of your code:
<#if var_usertags.data.items?has_content> <#list var_usertags.data.items as msgtag> <#assign utag = msgtag.text?string /> </#list> <#else> <#assign utag = "NONE" /> </#if>probably won't do what you are intending to, why? Because you're re-assigning the utag variable each time you #list over your tags, therefore even if you had multiple tags, your utag variable will always just contain one, the LAST one! The code can be written a bit more elegantly (and hopefully working as intended) like this:
<#assign utag = [] /> <#list var_usertags.data.items> <#items as msgtag> <#assign utag = utag + [msgtag.text] /> </#items> <#else> <#assign utag = ['NONE'] /> </#list>as you probably understood, the utag variable is now a sequence (think array...), when outputting it in your JS object, you'd simply do:
"keywords": "${utag?join(' ')?js_string}",notice the ?js_string, might be useful in that context, more info here.
you could also optimize your query a bit by just requesting the necessary information that you need, e.g. only the tag-text:
<#assign usertagQuery = "SELECT text FROM tags WHERE messages.id = '${msg_id}'" />but that's more a cosmetic thing, the query is correct as far as I can tell.
Sign in to react to this post