{"id":7742,"date":"2019-10-21T12:02:16","date_gmt":"2019-10-21T06:32:16","guid":{"rendered":"https:\/\/www.hiddentechies.com\/blog\/?p=7742"},"modified":"2020-10-08T19:41:04","modified_gmt":"2020-10-08T14:11:04","slug":"add-remote-javascript-stylesheet-prestashop","status":"publish","type":"post","link":"https:\/\/www.hiddentechies.com\/blog\/prestashop\/add-remote-javascript-stylesheet-prestashop\/","title":{"rendered":"How to add remote javascript &#038; stylesheet in PrestaShop 1.7"},"content":{"rendered":"<p>In this post I am going to explain how to add remote javascript &amp; stylesheet in PrestaShop 1.7.<\/p>\n<p>In PrestaShop 1.7+, it\u2019s easy to register custom assets on each pages. The major improvement is that you can easily manage them from your theme, without any modules.<\/p>\n<p>Lets see how to registering &amp; unregistering javascript as well as stylesheet easily.<\/p>\n<h4>Registering in modules<\/h4>\n<p><strong>1) In a front controller<\/strong><\/p>\n<pre class=\"lang:default decode:true \">$this-&gt;registerStylesheet(\r\n\t'module-modulename-style',\r\n\t'https:\/\/maxcdn.bootstrapcdn.com\/bootstrap\/3.3.7\/css\/bootstrap-theme.min.css',\r\n\t[\r\n\t  'media' =&gt; 'all',\r\n\t  'priority' =&gt; 200,\r\n\t]\r\n);\r\n\r\n$this-&gt;registerJavascript(\r\n\t'module-modulename-simple-lib',\r\n\t'https:\/\/maxcdn.bootstrapcdn.com\/bootstrap\/3.3.7\/js\/bootstrap.min.js',\r\n\t[\r\n\t  'priority' =&gt; 200,\r\n\t  'attribute' =&gt; 'async',\r\n\t]\r\n);<\/pre>\n<p><strong>2) In a module class<\/strong><\/p>\n<pre class=\"lang:default decode:true \">$this-&gt;context-&gt;controller-&gt;registerStylesheet(\r\n\t'module-modulename-style',\r\n\t'https:\/\/maxcdn.bootstrapcdn.com\/bootstrap\/3.3.7\/css\/bootstrap-theme.min.css',\r\n\t[\r\n\t  'media' =&gt; 'all',\r\n\t  'priority' =&gt; 200,\r\n\t]\r\n);\r\n\r\n$this-&gt;context-&gt;controller-&gt;registerJavascript(\r\n\t'module-modulename-simple-lib',\r\n\t'https:\/\/maxcdn.bootstrapcdn.com\/bootstrap\/3.3.7\/js\/bootstrap.min.js',\r\n\t[\r\n\t  'priority' =&gt; 200,\r\n\t  'attribute' =&gt; 'async',\r\n\t]\r\n);<\/pre>\n<h4>Unregistering<\/h4>\n<p>You can unregister assets! That\u2019s the whole point of an id. For example if you want to improve your theme\/module\u2019s compatibility with a module, you can unregister its assets and handle them yourself.<\/p>\n<p>Both unregisterJavascript and unregisterStylesheet methods take only one argument: the unique ID of the resource you want to remove..<\/p>\n<p><strong>1) In a front controller<\/strong><\/p>\n<pre class=\"lang:default decode:true \">$this-&gt;unregisterJavascript('js-identifier');\r\n$this-&gt;unregisterStylesheet('css-identifier');<\/pre>\n<p><strong>2) In a module class<\/strong><\/p>\n<pre class=\"lang:default decode:true \">$this-&gt;context-&gt;controller-&gt;unregisterJavascript('js-identifier');\r\n$this-&gt;context-&gt;controller-&gt;unregisterStylesheet('css-identifier');<\/pre>\n<p>Thats it!<\/p>\n<div class=\"angwp_12010 _ning_cont _ning_hidden _ning_outer _align_center responsive\" data-size=\"custom\" data-bid=\"12010\" data-aid=\"0\" style=\"max-width:800px; width:100%;height:inherit;\"><div class=\"_ning_label _left\" style=\"\"><\/div><div class=\"_ning_inner\" style=\"\"><a href=\"https:\/\/www.hiddentechies.com\/blog?_dnlink=12010&t=1775876252\" class=\"strack_cli _ning_link\" target=\"_blank\">&nbsp;<\/a><div class=\"_ning_elmt\"><img decoding=\"async\" src=\"https:\/\/www.hiddentechies.com\/blog\/wp-content\/uploads\/angwp\/items\/12010\/Banner-2.png\" \/><\/div><\/div><\/div><div class=\"clear\"><\/div>","protected":false},"excerpt":{"rendered":"<p>In this post I am going to explain how to add remote javascript &amp; stylesheet in PrestaShop 1.7. In PrestaShop 1.7+, it\u2019s easy to register custom assets on each pages. The major improvement is that you can easily manage them from your theme, without any modules. Lets see how to registering &amp; unregistering javascript as&#8230; <\/p>\n<div class=\"actions\"><a href=\"https:\/\/www.hiddentechies.com\/blog\/prestashop\/add-remote-javascript-stylesheet-prestashop\/\">Continue Reading<\/a><\/div>\n","protected":false},"author":1,"featured_media":7837,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[221,222,2139,2],"tags":[629,313,329],"_links":{"self":[{"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts\/7742"}],"collection":[{"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/comments?post=7742"}],"version-history":[{"count":1,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts\/7742\/revisions"}],"predecessor-version":[{"id":7743,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts\/7742\/revisions\/7743"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/media\/7837"}],"wp:attachment":[{"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/media?parent=7742"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/categories?post=7742"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/tags?post=7742"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}