Zum Inhalt springen

Unable to include JS file in Extension

Erstellt am 17. Januar 2019 · 2 Antworten · letzte Antwort am 18. Januar 2019

Tags: Fluid, JavaScript & AJAX, Frage, English

Meghna ·

Hi Experts,

I am new to TYPO3, I want to include bootstrap datetimepicker in my extension. Below is my code:

List.html

<head>
<script src="jhttps://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js">
</script>
<script src="jquery.datetimepicker.full.js"></script>
<script src="{f:uri.resource(path:'JS/datetimepicker.full.js')}"></script>
<script>$("#datetimepicker").datetimepicker();</script>
</head>
<f:section name="content">
<input type="text" id="datetimepicker"/>

setup.ts

page.includeJS.HsRoombooking = EXT:hs_roombooking/Resources/Public/JS/jquery.datetimepicker.full.js

This is include after plugin.tx_hsroombooking._CSS_DEFAULT_STYLE (). Could you let me know what is missing. The textfield is blank. Could you something to include datetimepicker in my extension.

Teisinger ·

Hello,

first it is not good to load your JS in the head tag (except with "defer" or async).
Next it can come to problems with your jQuery Script in the head tag, because what should be selected if the DOM-Tree is not fully loaded? To prevent this you can wrap your JS code like this:

;(function($, root, window, document) {	// Alias Technique
    $(function() {	// Equal to $(document).ready()
        // here your js code
    });
})(jQuery, this, window, document);

Next are you shure that your setup.ts is loaded? You can test this if you are in the backend -> Template -> Template analyse (or so)...

-----------

sorry for my english 😉