#registerEndOfPageHtml() directive

Hello, we tried to use the #registerEndOfPageHtml() directive but it doesn't work to register the scripts on the end of the page - and it gets echoed instead at the bottom.
What am I doing wrong?

I'm going through the docs here: https://community.telligent.com/community/11/w/developer-training/65122/using-ajax#When_should_I_use_JavaScript_in_widgets

  • Can you provide a sample of the code that is not working for you?

    Most of the widgets that are included in Community use this directive, have you reviewed any existing widgets to see how they are implemented and attempted to mimic one of those widgets?

  • Hi, we are using an Unfiltered HTML widget.

    Our code inside it is like so:

    #registerEndOfPageHtml()
        <script src="">unpkg.com/.../script>
    #end


    #registerEndOfPageHtml()
    <script type="text/javascript">
    //ajax preloader
    var $loading = $('.content-tagged,a.catego').hide();
    $(document)
      .ajaxStart(function () {
        $loading.hide();
        $(".spinner").show();
      })
      .ajaxStop(function () {
        $loading.fadeIn();
        //trigger click onload
            $(".button-reset").trigger("click");
        $(".spinner").hide();
      });
    </script>
    #end


    #registerEndOfPageHtml()
      <script type="text/javascript">
        jQuery('#toggle').css('cursor','pointer').click(function(){
            jQuery('#content').slideToggle('500');
            jQuery('#toggle').find('i').toggleClass('fa-toggle-off fa-toggle-on')
        });
      </script>
    #end

    However we find this once we save and publish (see at the end):

    Why is this? Do you have any idea?

    Thanks,

  • The unfiltered html widget does not support Or process any velocity syntax.  That is why you see it on the page, it’s just being interpreted as text.  In order to use the #registerEndOfPageHtml syntax you can create a custom widget in Widget Studio in the administration section of Community.  That same code should work as you are expecting in a custom widget.

  • Thank you!

    If I created a copy of the Unfiltered HTML widget under another name, and used it, would my code work as expected?

    Will the custom widget (even if it is a copy of the Unfiltered HTML widget) have automatically the necessary properties to parse the Velocity syntax?

    And finally, how to easily do such a copy? Is there an easy way for us to cipy over the Unfiltered HTML widget in the Widget Studio?

    Thanks

  • You don't need to copy the widget, you can create a new widget in Widget Studio and it will have all the same capability, all the script APIs will work, etc. I'd recommend checking out the Widget developer training for an introduction to working with widgets.