Forum Discussion

jchen's avatar
jchen
Boss
11 years ago

widget could not be displayed (custom widget)

Hi, all! We have a custom component, and when the user is logged out, we see a "This widget could not be displayed." message. I checked with Support and they said to make sure 

<#if !user.anonymous && (tkbBoards.board?size-1>0)> is in the code before the API call. 

 

Any idea on what else might be wrong? I'd appreciate any help!

  • Hi @jchen,

    Sorry, my bad ... typo there ... it should be this (without the "/" in the back of first line)

    <#if !user.anonymous>
    ... rest of code ...
    </#if>

     (Just FYI, the error description said line 1, column 22 ... that means a typo on the first line, 22nd character)

     

    Let us know if that works out for you

10 Replies

  • Inactive User's avatar
    Inactive User
    11 years ago
    I've gotten that error a number of times if there's some type of freemarker error in your code. Most of the time you get the crazy yellow/red long error message but not always. Maybe go through your code line/block by line/block and comment in/out things as you go through in order to test what will print out to the page without error?
  • JasonL's avatar
    JasonL
    Lithium Alumni (Retired)
    11 years ago

    hi jchen 

    Are you very certain that the <#if !user.anonymous> check is before any REST API call?

     

    Typically, you get  "widget could not be displayed" if there's a template exception. For instance, you're making a REST API as an anonymous user and your permission settings does not allow. 

     

    Hence, i concur with Support feedback, you need to put the <#if !user.anonymous> check prior to the REST API call

     

    But i'm a little intrigue with your check - tkbBoards.board?size because that seems indicate  that you're REST API call and assigning to variable tkbBoards. 

     

    Look out for statements like this:

    <#assign tkbBoards = rest("/xxxx/...") />

    If you do see this line, you need to put <#if !user.anonymous> prior to this line.

    (not exactly sure what your code does but you should probably separate this <#if tkbBoards.boards?size check till after the REST API call?)

     

    Hope that helps

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

  • Can you please post your code here, not the entire code, but just a snippet where you have used this condition. This usually is the case when the users don't have the permissions to make the API calls, other than that, I will need to have a look at your code.

  • jchen's avatar
    jchen
    Boss
    11 years ago

    Here's the beginning of my code

    <#assign tkbBoards = rest("/categories/id/demandforce-tkb/boards/nested?restapi.response_style=view").boards/>
    
    <#if !user.anonymous && (tkbBoards.board?size-1>0)>
    <#assign boardIdList=[] />
    <#list tkbBoards.board as board>
    	<#assign boardId = board.id/>
    	<#assign boardIdList = boardIdList + [boardId] />
    </#list>

     I tried adding <#if !user.anonymous && (tkbBoards.board?size-1>0)> before the first line and got this 

    Freemarker template 'preview' parsing failed:

    ParseException:Parsing error in template "preview" in line 55, column 16:
    Unclosed #if when the end of the file was reached.
  • HaidongG's avatar
    HaidongG
    Lithium Alumni (Retired)
    11 years ago

    Hi jchen ,

     

    since you have put 

    <#if !user.anonymous && (tkbBoards.board?size-1>0)>

     on the top of your code, you may have to put

    </#if>

     to the end of the code.

     

  • JasonL's avatar
    JasonL
    Lithium Alumni (Retired)
    11 years ago

    hi jchen,

    i see two issues.

     

    Issue 1: no closing #if

    for this message:

    Unclosed #if when the end of the file was reached.

    you need to put the closing </#if> at the bottom on the page

     

    Issue 2: check for tkbBoards cannot be done before the var assignment

    Try something like this:

    - check if user is not anonymous before making the REST api call 

    - check the tkbBoards size only after the REST api call

    - after the rest of the code remember to put the closing </#if> (and you need 2 now as there's 2 #if)

    <#if !user.anonymous />
    <#assign tkbBoards = rest("/categories/id/demandforce-tkb/boards/nested?restapi.response_style=view").boards/>
    
    <#if (tkbBoards.board?size-1>0)>
    <#assign boardIdList=[] />
    <#list tkbBoards.board as board>
    	<#assign boardId = board.id/>
    	<#assign boardIdList = boardIdList + [boardId] />
    </#list>
    
    ... rest of the code here ...
    
    </#if>
    </#if>

     

  • jchen's avatar
    jchen
    Boss
    11 years ago

    Thank you guys for your suggestions! JasonL , I did as you suggested but get this error

     

    Freemarker template 'preview' parsing failed:
    ParseException:Parsing error in template "preview" in line 1, column 22:
    Encountered "/>", but was expecting one of:
        ">"
        "."
        "["
        "("
        "?"
        "!"
        <TERMINATING_EXCLAM>
        "??"
        "+"
        "-"
        "*"
        "/"
        "%"
        "!="
        "="
        "=="
        ">="
        <ESCAPED_GTE>
        ">"
        <ESCAPED_GT>
        <LESS_THAN_EQUALS>
        <LESS_THAN>
        ".."
        <AND>
        <OR>

     Not sure what that means...any ideas? Sorry about all the questions, I'm fairly new at this!

  • JasonL's avatar
    JasonL
    Lithium Alumni (Retired)
    11 years ago

    Hi @jchen,

    Sorry, my bad ... typo there ... it should be this (without the "/" in the back of first line)

    <#if !user.anonymous>
    ... rest of code ...
    </#if>

     (Just FYI, the error description said line 1, column 22 ... that means a typo on the first line, 22nd character)

     

    Let us know if that works out for you

  • Hello there, 

    Actually i faced this problem many many times, but at the end i found that there's no error in the code, there's no error at all, this error caused by a permissions limitation! all you have to do is changing the permissions in the "Admin" tab, and then everything should go as you expected.

     

    :smileyhappy: