Forum Discussion

giannag's avatar
giannag
Adept
13 years ago

Freemarker for Category's Language Default?

Hello!

 

I am writing an if/else statement for when to display Japanese test or images on our community.  In psudocode:

"IF the user's personal language setting is set to Japanese OR the page's default language is Japanese {

do this HTML

}

ELSE {

do that HTML

}

 

Right now I am using:

<#assign lang = rest("/users/id/${user.id?c}/profiles/name/language").value />
<#if lang == "ja" || http.request.url?contains("/t5/%E6%97%A5%E6%9C%AC%E8%AA%9E%E3%83%95%E3%82%A9%E3%83%BC%E3%83%A9%E3%83%A0/ct-p/japanese-forum")>

<!--DO THIS HTML-->

<#else>

<!--DO THAT HTML-->

</#if>

 

This seems rather clunky to me and has several problems.  Notably, that the URL I'm checking is only the top-level Japan category page and does NOT apply to all the Japan category's boards and posts (which it should).

 

I was sent this nice bit of code for grabbing a user's personal language setting:

<#if settings.name.get("profile.language") = "ja"> 

but now I need to figure out how to get a page's default language (so ALL posts and boards in the Japan category display my specified HTML code).  I've got this REST call:

/restapi/vc/boards/id/boardid/settings/name/profile.language

but is there something out there more elegant?  More similar to the get() function above?

 

Thank you!

Best,

Gianna

 

 

  • Just make sure that in both code examples the condition of the if-statement is compared correctly.

    There should be two equation signs when comparing a variable with a string:

    <#if (settings.name.get("profile.language") == "ja") || (coreNode.settings.name.get("profile.language") == "ja") > 

     Maybe that's why it didn't work in your initial testing when comparing agains settings.name

3 Replies

  • KaelaC's avatar
    KaelaC
    Lithium Alumni (Retired)
    13 years ago
    <#if (settings.name.get("profile.language") = "ja") || (coreNode.settings.name.get("profile.language") = "ja") >

    This should check both the user and the board/category/whatever node. I think just setttings.name... would work, too, but this is explicit
  • Claudius's avatar
    Claudius
    Boss
    13 years ago

    Just make sure that in both code examples the condition of the if-statement is compared correctly.

    There should be two equation signs when comparing a variable with a string:

    <#if (settings.name.get("profile.language") == "ja") || (coreNode.settings.name.get("profile.language") == "ja") > 

     Maybe that's why it didn't work in your initial testing when comparing agains settings.name

  • giannag's avatar
    giannag
    Adept
    13 years ago

    Thank you!!!  This is just what I was looking for!!