It it okay to use Facebook SDK directly in the layout.tpl file in NAVI press, Subrion version 3.3.x?

Discussion in 'Subrion CMS Plugins Discussion' started by projectashenfire, Jul 25, 2016.

  1. Now that I have Facebook login working, I would like to ask a question that is less involved.

    Statement to support question

    Web authors are instructed by Facebook to use the Software Developers Kit and implant it on any page they plan on using Facebook integration, for instance, the LIKE button.

    In my example, I am using it for WebPages, not IOS; etc.

    My kit involves java:

    <div id="fb-root"></div>
    <script>(function(d, s, id) {var js, fjs = d.getElementsByTagName(s)[0];if (d.getElementById(id)) return;
    js = d.createElement(s); js.id = id;
    js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.7&appId=enterappid";fjs.parentNode.insertBefore(js, fjs);}(document, 'script', 'facebook-jssdk'));</script>

    I am instructed to put that code right after the <body> tag.
    I have done this and my site works.

    QUESTION

    Now that I have established a basic concept, I want to simplify this with NAVI press and NOT COPY SDK CODE to every page I have created.

    Not all of my pages include <html> </html> yet I want to still use social media integration like FB.

    Is it okay to put my SDK code directly into my layout.tpl file?

    I assume it should work, but I need to know if this might break or alter the function of Subrion.

    If Subrion coders are 'shaking their heads' and saying 'oh no, what are you doing!' I will work
    on something else then.
    Last edited: Aug 10, 2016
    Greg likes this.
  2. Greg

    Greg Super Moderator

    I don't see any reason placing it directly in the layout.tpl file should not work.
    I would place the:
    Code (Javascript):
    <script>(function(d, s, id) {var js, fjs = d.getElementsByTagName(s)[0];if (d.getElementById(id)) return;
    js = d.createElement(s); js.id = id;
    js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.7&appId=enterappid";fjs.parentNode.insertBefore(js, fjs);}(document, 'script', 'facebook-jssdk'));</script>
    Either just before the </head> or </body>.
  3. Andrew_G.

    Andrew_G. Staff Member

    Hi @projectashenfire ,

    Seems to be a bit obsolete reply, anyhow.

    You can insert your js code directly to .tpl files and it will work.
    We recommend to do it by using our built-in smarty functions to avoid multiple js files / code inclusions:
    {ia_print_js} function for external js file inclusion
    {ia_add_js} function for adding of js code

    Thanks!
  4. Excellent. Thank you.
    I of course have zero java experience.

    Are you saying that if I used the FB code and pasted it into a file Facebook.inc (inclusion file),
    that I would 'call' the inclusion file with ia_print_js?
    If so, I would put the 'call' function inside my .tpl?

    If that is true, then I can see what I can learn to make it happen.

Share This Page