Hello there community,
I am porting existing code from plain old Javascript to a Meteor project.
There is a component where I have a Facebook button and all the Javascript for that was originally in a separate file which was loaded by a plain old <script>
tag in the main original HTML file.
I am making a component for such button and placing the <script>
in the HTML file of the template works fine:
<template name="facebookPageIntegration">
<!-- Facebook -->
<script type="text/javascript" src="/assets/js/social/facebook/login/facebookRegistrationLib.js"></script>
<div id="fb-root"></div>
[...]
However, I think it would be cleaner to place that code inside the .JS template file (template.html
+ template.js
):
import { Template } from 'meteor/templating';
import './facebookPageIntegration.html';
[...]
Template.facebookPageIntegration.onRendered(function() {
[...]
});
[...]
// Code from the embedded JS file.
function facebookRegistrationLib() {
alert('Invoked from the template HTML file!');
}
export { facebookRegistrationLib }
This last part does not seem to work. Tried just exporting the functions but resulted undefined when invoked.
My question is: what is the right way I should be porting this code to Meteor?
Thanks in advance for your time!