nVelocity suggestions

nVelocity suggestions

This question is not answered

There are times when in a widget there is a need to add javascript to the header or to the top of a page

#RegisterTopOfPage

#RegisterHeader

would be handy

Also $core_v2_page.RenderThemeHeaders  should have more parameters so you can turn things like title rendering off.

Cheers,

Rob

All Replies
  • Thanks for this feedback, I will forward it on and see what we can get done for you.

  • Hi Robert I have sent a post to your company forum where we may be able to chat a bit more in detail about these.
     
    Thanks!
     
    Patrick Mason
    Development Lead- Extensibility
    o: 214.420.1329
    telligent.com
     
    From: Wyatt Lyon Preul [mailto:bounce-wpreul@communities.telligent.com]
    Sent: Friday, June 08, 2012 9:40 AM
    To: discussion_evolution@communities.telligent.com
    Subject: RE: [Telligent Evolution Platform Discussion] nVelocity suggestions
     

    Thanks for this feedback, I will forward it on and see what we can get done for you.

  • Hi Patrick,

    I also find there is a regular need for this. Please can you let me know if this is possible also?

    Thanks

    Adam

  • You should be able to do this via a widget extension. See the below sample.  (Note, I've typed this straight into the editor - apologies for any typos)

    var page = HttpContext.Currrent.Handler as System.Web.UI.Page;
    if (page != null)
    {
      page.Head.Controls.Add(new Literal("<!--This markup goes in the head-->");
      page.ClientScript.RegisterScriptBlock(this.GetType(), "key", "<script>alert('hello world');</script>");
    }
  • Thanks Alex, I guess we could do it like this also (how we used to in TC5.6 and below):

    Type cstype = oThis.GetType();

    System.Web.UI.ClientScriptManager cs = currentPage.ClientScript;

    if (!cs.IsStartupScriptRegistered(cstype, scriptId))

    {

       String script = string.Format("<script type=\"text/javascript\" src=\"{0}\"></" + "script>", "/path/to/script.js");

       cs.RegisterStartupScript(cstype, scriptId, script, false);

    }

    Is this likely to be supported ootb in TC7 with #RegisterHeader ?

    Thanks

    Adam

  • I don't think you want to use RegisterStartupScript.  If I recall correctly, RegisterStartupScript registers the script at the end of the page, so you might as well use #RegisterEndOfPageHtml .  (I may be wrong, I always get confused about where each ClientScriptManager method actually registers .

    Also note if you want to register a CSS style in the header, you can use $core_v2_page.AddLink

    e.g. $core_v2_page.AddLink("stylesheet", $core_v2_widget.GetFileUrl('anythingslider.css'), "%{}")

  • The 7.0 support for this is via a plugin, not currently using a new directive.  So it would apply to all pages -- not just pages that register a header via an extension.

    In what scenarios would registering a header/topOfPageHtml be useful?  I just want to ensure that I fully understand the need.