Adding code into index.template

Started by treehugger, January 13, 2014, 09:08:54 AM

Previous topic - Next topic

treehugger

Am trying to add a code to make our Facebook feed show on our forum. I've added a SP block but when I try adding this code to the theme index.templete.php I lose the whole page.

AT PRESENT I HAVE:
// Output any remaining HTML headers. (from mods, maybe?)
echo $context['html_headers'];

   echo '
</head>
<body>';
}

function template_body_above()

AND NEED TO ADD (....ideally right after the opening <body> tag.):

<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_GB/all.XXXXXXXXX";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>


Do I take ';} out after body - do I add them in after closing the script - help please.

Shambles

It might be as simple as replacing

}(document, 'script', 'facebook-jssdk'));</script>

.. with

}(document, \'script\', \'facebook-jssdk\'));</script>

Arantor

And putting it inside the function not after it.

treehugger

Thank you for your replies gentlemen but I haven't got a clue what you are talking about.  :-[

I'm guessing I put the whole of the script in after changing the last line?

Does "putting it inside the function not after it".mean put it before <body>'; }

Arantor

No, it means putting it before the } but after the semi colon.

treehugger

Thanks for the reply. I put in (without the XXXX of course)

</head>
<body>';
<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_GB/XXXXXXX";
  fjs.parentNode.insertBefore(js, fjs);
}(document, \'script\', \'facebook-jssdk\'));</script>
}


and got: Template Parse Error! It seems something has gone sour on the forum with the template system.
As soon as I took the new code out and went back to

   echo '
</head>
<body>';
}


everything was fine again.

Arantor

That's because you've spliced it into the PHP and not the HTML.

</head>
<body>
<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_GB/XXXXXXX";
  fjs.parentNode.insertBefore(js, fjs);
}(document, \'script\', \'facebook-jssdk\'));</script>';
}

treehugger


sathirtythree

you can also replace the single quotes in that with double quotes.

Advertisement: