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

  • 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:

  • Inactive User's avatar
    Inactive User
    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)

    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

      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)

        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.