Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Magento 2 Cookbook

You're reading from   Magento 2 Cookbook Exploring Magento 2 in the form of recipes

Arrow left icon
Product type Paperback
Published in Mar 2016
Publisher
ISBN-13 9781785887062
Length 342 pages
Edition 1st Edition
Languages
Concepts
Arrow right icon
Toc

Table of Contents (10) Chapters Close

Preface 1. Installing Magento 2 on Apache and NGINX 2. Magento 2 System Tools FREE CHAPTER 3. Enabling Performance in Magento 2 4. Creating Catalogs and Categories 5. Managing Your Store 6. Creating a Magento 2 Theme 7. Creating Magento 2 Extensions – the Basics 8. Creating Magento 2 Extensions – Advanced Index

Adding CSS/JS to pages


Adding your own CSS or JS to every or specific page can also be done through a layout XML file. The source of a file that you want to include can come from the following:

  • An external source hosted remotely

  • Module-specific, which is mainly used by JavaScript

  • Theme-specific, which is mainly used when adding CSS but can also be used to add custom JavaScript

Getting ready

In order to include CSS or JavaScript to a page, you first need to know where you want to include your files and where the file is located that you want to include. In this recipe, we will see how to include both an external CSS and JavaScript file and a theme JavaScript and CSS file.

How to do it…

This recipe is based on the theme created in the Creating a new theme recipe of this chapter.

  1. To add a new source (CSS or JS) to all pages, the configuration is done through the default_head_blocks.xml file. It is also possible to add it to a single page only through the layout file for that layout handle:

    app/design...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime