Forum Discussion

chrigu's avatar
chrigu
Guide
12 years ago

Problems when using text.format

Hi there

 

I defined some custom language keys e.g. some.text = "lorem ipsum" in two different languages.

 

In the code I'm trying to get the value by:

 

text.format{"some.text"}

 

Now the funny thing is, is that when I use text.format it works at some part in a custom component and in some other I get a

 

Expected hash. text evaluated instead to freemarker.template.SimpleScalar on line 117, column 23 in preview. The problematic instruction: ---------- ==> ${text.format("some.text")} [on line 117, column 21 in preview] ----------

 

error.

 

Has anyone any clue what this could be as it is driving me nuts.

 

Thanks!

chris

  • Are you assigning a value to the varible "text" elsewhere in your code, perhaps in one of the macros you've created? If so, I'd suggest renaming the variables you're using because you're likely overwriting the "text" custom context object that already exists. Alternately, you could create a namespace for your macros, which might help prevent them from overwriting your main namespace variables:

    http://freemarker.sourceforge.net/docs/dgui_misc_namespace.html

8 Replies

  • AdamN's avatar
    AdamN
    Khoros Oracle
    12 years ago

    Would you be able to give any additional context from the line of the component where it's failing? Are you trying to assign the text value to some other variable?

  • KaelaC's avatar
    KaelaC
    Lithium Alumni (Retired)
    12 years ago
    If it's possible to give us the full line that text format call is on, it would be really helpful. Also, are you working in a component or endpoint? Not all types of files have the text context. For example, the text file itself does not use that notation.
  • chrigu's avatar
    chrigu
    Guide
    12 years ago

    I'm working in a custom component

     

    ....
    <#if latest_news??>
    <!-- floated stuff -->
    <div id="latest-news" class="overview-part">
    <div class="overview-part-header">
    <h2>${text.format("site.news")}</h2>
    <h3><a href="${latest_news.topic.@view_href}">${latest_news.topic.subject}</a></h3>
    <@comments no_comments=latest_news.count?number link=latest_news.topic.@view_href />
    <div style="clear:both"></div>
    </div>
    <@blog_overview latest_news.topic.teaser latest_news />

    <div style="clear:both"></div>
    </div>
    </#if>

    <#assign popular_idea = idea_pop_messages.thread.messages />
    <#assign idea_body = rest("${popular_idea.topic.@href}").message.body />
    <#if popular_idea??>
    <div id="popular-idea" class="overview-part">
    <div class="overview-part-header">
    <h2>${text.format("site.news")}</h2>
    <h3><a href="${popular_idea.topic.@view_href}">${popular_idea.topic.subject}</a></h3>
    <@comments no_comments=popular_idea.count?number link=popular_idea.topic.@view_href />
    <div style="clear:both"></div>
    </div>
    <@excerpt text=idea_body url=popular_idea.topic.@view_href/>
    </div>
    </#if>

    ....

     

    The first occurance of ${text.format("site.news")} is displayed correctly while the second in the popular-idea div throws the exception.

     

    thanks

  • ChiaraS's avatar
    ChiaraS
    Lithium Alumni (Retired)
    12 years ago

    I see an extra "}" in the second occurrence... that may be the reason

  • chrigu's avatar
    chrigu
    Guide
    12 years ago

    thanks for pointing that out, but it was just a copy/paste error when I posted it to the forum :) On my system it's with just one parenthsis and correct freemarker code.

     

    But now I corrected it above.

  • ChiaraS's avatar
    ChiaraS
    Lithium Alumni (Retired)
    12 years ago

    could you also copy paste the exception message here? that may give some more hints...

  • AdamN's avatar
    AdamN
    Khoros Oracle
    12 years ago

    Are you assigning a value to the varible "text" elsewhere in your code, perhaps in one of the macros you've created? If so, I'd suggest renaming the variables you're using because you're likely overwriting the "text" custom context object that already exists. Alternately, you could create a namespace for your macros, which might help prevent them from overwriting your main namespace variables:

    http://freemarker.sourceforge.net/docs/dgui_misc_namespace.html

  • chrigu's avatar
    chrigu
    Guide
    12 years ago

    thanks that fixed it. I thought that macros would define their own namespace.