I have a javascript file that I would to add to discourse, but I am not sure how. Am I required to create a plugin to include a js file or can I include the file in the source code? Either way, I am not sure how to accomplish this.
If what you need is to embed, in every Discourse page, a tag linking to an external resource, you need to do the following:
Create a theme component and include it to all your themes
In your theme component, click "Edit CSS/HTML"
In the </head> section, enter your <script src="..."></script> code and click "Save"
In Discourse setting content_security_policy_script_src, add the full url of the script
The full doc is here.
I was able to achieve this by adding the following code <script async src="url-here" data-url="url-here"></script> Into the </head> section of /admin/customize/themes
Try using this :
<script src="**URL**"></script> under the head section.
The URL of the external script file.
Possible values:
An absolute URL - points to another web site (like src="http://www.example.com/example.js")
A relative URL - points to a file within a web site (like src="/scripts/example.js")
Related
So I have a website, https://coolkids.gq. I want to be able to add a certain line of code to every single HTML file on the website using another HTML, JavaScript or PHP file, but I am not sure how to do this.
How would I be able to write a script to add a line of custom code to every HTML page on my website?
Edit: As pointed out by charlieftl, I should clarify that all files are saved in either the /htdocs folder or in a folder inside of that.
yes you can, just make some folder named include or whatever and create for example loginForm.html sth like
<div>
<form>
....
</form>
</div>
and in pages where you want to put it use
<?php require('./include/loginForm.html') ?>; in place where you need it
Of course it need to be PHP page.
Good thing is to have also included header and footer in external html and include it on every php page ;D
if you want some js script in every page you need to add it manualy:
<script src="js/main.js"></script>
but it can be included in footer.
I downloaded some realtime css editor and I have a hard time figuring out how to link it to my other pages.
I have a file called cssit.js (that's a css editor) and if I put it in a same folder as my page, it works fine. However, if I wish to link to that script from pages that are in other folders, I don't know how to.
Example: My page is in images/index.php, but that script is in scripts/javascript/cssit.js
How would I link to index.php that script?
// images/index.php
<script src="../scripts/javascript/cssit.js">
// another/dir/index.php
<script src="../../scripts/javascript/cssit.js">
Or, maybe an easier way is to use absolute paths. Assuming scripts/javascript is at the root of your website:
// images/index.php
<script src="/scripts/javascript/cssit.js">
// another/dir/index.php
<script src="/scripts/javascript/cssit.js">
So Google tells me to do this:
Paste your snippet (unaltered, in it’s entirety) into every web page you want to track. Paste it immediately before the closing </head> tag.
I understand this part, but as I'm including my header and footer, I guess this is not what I'm supposed to do.
If you use templates to dynamically generate pages for your site (like if you use PHP, ASP, or a similar technology), you can paste the tracking code snippet into its own file, then include it in your page header.
So I guess this is what I'm talking about(?), but I don't really get exactly where they want me to put the snippet. Do I put it in my header.php file once right before the closing </head> tag and then include the header.php file into every page or do I have to put the snippet directly in on every page? Incase I have to put the snippet in on every page, where exactly do I put it? Could someone please give me an example of this?
You can paste the Google Analytics Javascript snippet into its own file, call it ga.js for example.
Then in your header.php file, right before you close the tag, include that Javascript file, like so:
<script type="text/javascript" src="ga.js"></script>
This will load the GA code in your head section every time you load the header.php file. This should happen to every page that you load header.php automatically.
If you already have split your header, that I guess is included into you other html or php files, in it's own file and it includes the </head> tag, then you can put a script right above it.
This would look something like this:
[...]
<script>
<!-- Your personal google analytics snippet -->
</script>
</head>
Then all sites, that include your header.php, also load the snippet from analytics and get tracked.
i'm starting with requireJS and need some help to proceed with its implementation.
My site is built following the defaults:
header.html (always the same, containing the requiredjs script tag)
$pageMain (always variable - $pageAbout, $pageContact...)
footer.html (always the same)
I need to load specific js file in different pages from my site, but i have only one header which contains the tag to set my required files.
<script data-main="js/main" src="js/lib/require.js"></script>
When my page is $pageAbout i need to load $pageAbout.js instead $pageMain.js
I'm still not able to do this.
Checking the https://github.com/requirejs/example-multipage# i understood how it works, but in my case, i coudn't do it because i specify the script tag only once in the header.html
Any suggestion ?
I don't know if i was clear in my question. Please let me know to better explain.
There are various solutions here, depending on what you can easily edit.
You could change the script tag in the header, based on the current page. I am assuming from your description that this is not possible.
If you have to always load the same js/main script, you could use that as a switch between different page-specific modules:
// js/main.js
define(function() {
var pageId = getPageId();
require('js/' + pageId);
});
This depends on being able to get the page id when the header loads - either through a JS variable you can set before the header is loaded, or by parsing the URL, or through some other means.
You can simply drop the script tag from the header and include it in the variable body of your page. Script tags can appear anywhere in the document.
You could drop the data-main attribute from the header script tag (so that the header just loads the RequireJS library), then have a script tag in your page body to load the page-specific module:
<script> require('js/pageAbout'); </script>
Any of these should work - the last two are probably simplest. The RequireJS docs are very prescriptive, but there are many paths to a working implementation - you don't have to do it the recommended way.
I'm using rails 2, and in one of the plugin I'm working on, I found this weird issue, I've TinyMce 4 customized text editor.
I've loaded the script at the beginning of the page, in the new form.
<script type="text/javascript" src="../tinymce/tinymce.min.js"></script>
TinyMce loads normally, and works completely fine.
In case of edit form the same script tag above doesn't work, I've move up 1 level to load it, I mean
<script type="text/javascript" src="../../tinymce/tinymce.min.js"></script>
Out of curiosity, what is going on here?
Folder Sturucture.
>>plugin_name
>>app
>>config
>>db
>>lib
>>public
>>images
>>javascripts
>>stylesheets
>>tinymce
I suspect your new page has a url like : /post/new whereas your edit page has a url like /post/1/edit
Because the edit URL has an extra / you need to go up an extra level in the relative path in your script tag.
Try changing the TinyMCE include to be an absolute path, not a relative one:
<script type="text/javascript" src="/tinymce/tinymce.min.js"></script>