Redirect Page using Velocity Template Language

Redirect Page using Velocity Template Language

This question is answered

I am writing a widget in Telligent Community 6.0 using Velocity Template Language. I am not able to redirect the user using the following code. Could someone tell me what is the right way to redirect.

#set($url = '/p/library.aspx')

$core_v2_page.Redirect($url)  ##does not work

Verified Answer
  • I was able to resolve the issue. I think changes were not instantIy applied. The same code worked fine after about 5 minutes. Thanks for your help.

All Replies
  • What do you mean it does not work?  Is nothing happening?  Are you getting an error?  Any exceptions in the exception log.

    This seems to work fine (assuming you have created a site content page with the urlkey library).

    Also, you may want to add a check that your widget is not in preview (edit) mode.

    #if (!$core_v2_widget.IsInWidgetPreviewMode)

      #set($url = '/p/library.aspx')
      $core_v2_page.Redirect($url)
    #end

  • I checked the widget and its not in preview mode. I commented everything in my velocity script code and added just this single line. When I add this widget to a page, I get a red box saying "Object reference not set to an instance of an object".

    $core_v2_page.Redirect('gjaura6420.osisoft.int/.../libraryinfo.aspx&) ##its a valid url

  • That url is not fully qualified, so you will be redirected to path inside your current site.

    for instance if you placed this widget on telligent.com and added:

       $core_v2_page.Redirect('telligent.com')

    you would be redirected to telligent.com/telligent.com

    This would be the correct redirect:

       $core_v2_page.Redirect('http://telligent.com')

    --------------------------------------------------------------------------------

    The intent of  #if (!$core_v2_widget.IsInWidgetPreviewMode)  is to provide the ability for a widget to behave differently when you are in edit mode (when you are placing the widget).  For example, if the logout widget did not check for preview mode, when you tried to edit the logout page you would be logged out of the site.   That is why I suggested it in this instance.  When you are editing the page you place this widget on, you would never want the redirect to execute.  Using the IsInWidgetPreviewMode call you could provide an alternate functionality, maybe outputting the url that would have redirected too as text.

  • I was able to resolve the issue. I think changes were not instantIy applied. The same code worked fine after about 5 minutes. Thanks for your help.

  • I was able to resolve the issue. I think changes were not instantIy applied. The same code worked fine after about 5 minutes. Thanks for your help.