SlideShare a Scribd company logo
Frontend Development in
Magento 2
Arjen Miedema
twitter.com/arjenmiedema_nl | linkedin.com/in/arjenmiedemanl
Magento 2 Arrived!
Arjen Miedema
twitter.com/arjenmiedema_nl | linkedin.com/in/arjenmiedemanl
Less & RequireJS - Frontend Development in Magento 2
Less & RequireJS - Frontend Development in Magento 2
- Ever used Magentoโ€™s RWD theme? Then you met SASS
- SASS !== LESS
- Requires NodeJS, easy to install
- Use variables, nested styles, functions, etc.
- Watch usefull tutorials online on YouTube
Less
nav {
margin: 50px auto 0;
width: 750px;
ul {
padding: 0;
margin: 0;
li {
display: inline-block;
&:hover {
background-color: #5e5b56;
}
}
}
}
Less
nav { margin: 50px auto 0; width: 750px; height: 45px; }
nav ul { padding: 0; margin: 0; }
nav ul li { display: inline-block; }
nav ul li:hover { background-color: #5e5b56; }
Less
//
// Primary button
// ---------------------------------------------
.action-primary {
.lib-button-primary();
.lib-css(border-radius, @button__border-radius);
}
Less
.lib-button-primary(
@_button-line-height: @button-primary__line-height,
@_button-width: @button-primary__width,
@_button-margin: @button-primary__margin,
@_button-padding: @button-primary__padding,
(..)
) {
.lib-button(
@_button-line-height: @_button-line-height,
@_button-width: @_button-width,
@_button-margin: @_button-margin,
@_button-padding: @_button-padding,
(..)
);
}
Less
.lib-css(
@_property,
@_value,
@_prefix: 0
) when (@_prefix = 1)
and not (@_value = '')
and not (@_value = false)
and not (extract(@_value, 1) = false)
and not (extract(@_value, 2) = false)
and not (extract(@_value, 3) = false)
and not (extract(@_value, 4) = false)
and not (extract(@_value, 5) = false) {
-webkit-@{_property}: @_value;
-moz-@{_property}: @_value;
-ms-@{_property}: @_value;
}
Less
.example-button-4 {
.lib-button-primary(@_button-margin: 3px);
&:active {
box-shadow: inset 0 3px 1px rgba(0,0,0,.29);
}
&.example-button-5 {
.lib-button-s();
color: #fff;
&:hover,
&.active {
color: #fff;
}
}
}
Less
RequireJS
RequireJS
- Magento now uses AMD (Asynchronous Module Definitions)
- Easily manage JavaScript dependencies
- Asynchronous loading === faster page load
- JavaScripts are not initialized via layout XML files
Thanks to Filip Svetliฤiฤ‡ (Watch on YouTube)
RequireJS
<html>
<head>
<!--
data-main attribute tells require.js to load
scripts/main.js after require.js loads.
-->
<script src="js/main.js" data-main="main"></script>
</head>
<body>
<div class="wrapper">
(...)
</div>
</body>
</html>
RequireJS
require.config({
baseUrl: 'js/lib',
paths: {
// the left side is the module ID,
// the right side is the path to
// the jQuery file, relative to baseUrl.
// Also, the path should NOT include
// the '.js' file extension. This example
// is using jQuery 1.9.0 located at
// js/lib/jquery-1.9.0.js, relative to
// the HTML page.
jquery: 'jquery-1.9.0'
}
});
RequireJS
require.config({
map : {
'*' : {
'jquery': 'js/jquery-1.12.0'
},
'jquery-bxslider' : {
'jquery': 'js/jquery-1.9.1'
}
}
});
RequireJS
<input id="search" data-mage-init= '{"quickSearch":{ "formSelector":"
#search_mini_form", "url":"http://magento2.dev/search/ajax/suggest/",
"destinationSelector":"#search_autocomplete"} }' type="text" name="q"
value="" placeholder="Search entire store here..." class="input-text"
maxlength="128" role="combobox" aria-haspopup= "false" aria-autocomplete= "
both" autocomplete="off"/>
RequireJS
{
"quickSearch": {
"formSelector":"#search_mini_form",
"url":"http://magento2.dev/search/ajax/suggest/",
"destinationSelector":"#search_autocomplete"
}
}
var config = {
map: {
'*': {
quickSearch: 'Magento_Search/form-mini'
}
}
};
Loads file: vendor/magento/module-search/view/frontend/web/form-mini.js
RequireJS
define([
'jquery',
'underscore',
'mage/template',
'jquery/ui',
'mage/translate'
], function ($, _, mageTemplate) {
'use strict';
// Here is all JavaScript to handle the search autocomplete
});
RequireJS
<script type="text/x-magento-init">
{
"*": {
"mage/cookies": {
"expires": null,
"path": "/",
"domain": ".www.mydomain.com",
"secure": false,
"lifetime": "3600"
}
}
}
</script>
RequireJS
<script type="text/x-magento-init">
"#main-container": {
"navigation": "{ navigation-json-configuration }",
"accordion": "{ accordion-json-configuration }"
},
"*": {
"pageCache": "{ page-json-configuration }"
}
</script>
http://gruntjs.com/
http://knockoutjs.com/
More Information
Magento 2 & Less:
http://devdocs.magento.com/guides/v2.0/frontend-dev-guide/css-topics/css-
preprocess.html
Magento 2 & RequireJS:
http://devdocs.magento.com/guides/v2.0/javascript-dev-guide/javascript/js-
resources.html
http://devdocs.magento.com/guides/v2.0/javascript-dev-
guide/javascript/js_init.html
Thanks!

More Related Content

PPTX
Magento 2 Theme Trainning for Beginners | Magenest
PPS
Asp.Net 2.0 Presentation
PDF
Refactoring to a Single Page Application
PDF
Sergii Shymko - Code migration tool for upgrade to Magento 2
PPTX
Web Development Today
PPTX
Introduction to Web Development
PPT
Jsp Comparison
PPTX
Single Page Application (SPA) using AngularJS
Magento 2 Theme Trainning for Beginners | Magenest
Asp.Net 2.0 Presentation
Refactoring to a Single Page Application
Sergii Shymko - Code migration tool for upgrade to Magento 2
Web Development Today
Introduction to Web Development
Jsp Comparison
Single Page Application (SPA) using AngularJS

What's hot (20)

PPTX
Empowerment Technologies Lecture 11 (Philippines SHS)
PDF
Front End Development in Magento
ODP
A Good PHP Framework For Beginners Like Me!
PPTX
Advanced Technology Days 15 - Visual Studio Productivity
PDF
Introduction to Using PHP & MVC Frameworks
PDF
Rongde Qiu-DDsmile-2015.1.25
PPTX
Twitter bootstrap tutorial
ODP
Problemen oplossen in Joomla - Joomladagen 2014
PPTX
Introduction to ASP.NET Core
PDF
Levent-Gurses' Introduction to Web Components & Polymer
PPTX
Front-End Web Development
PPTX
Client Building Functional webapps.
PDF
Blazor - The New Silverlight?
ODP
Fresh Start HTML & CSS
PPTX
How to Install Magento 2 on XAMPP Server localhost.
PPT
Javascript(2)
ย 
PPTX
PHP Summer Training Presentation
PDF
Principles of MVC for PHP Developers
PDF
Introduction to Browser Internals
PDF
Here Be Dragons - Debugging WordPress
Empowerment Technologies Lecture 11 (Philippines SHS)
Front End Development in Magento
A Good PHP Framework For Beginners Like Me!
Advanced Technology Days 15 - Visual Studio Productivity
Introduction to Using PHP & MVC Frameworks
Rongde Qiu-DDsmile-2015.1.25
Twitter bootstrap tutorial
Problemen oplossen in Joomla - Joomladagen 2014
Introduction to ASP.NET Core
Levent-Gurses' Introduction to Web Components & Polymer
Front-End Web Development
Client Building Functional webapps.
Blazor - The New Silverlight?
Fresh Start HTML & CSS
How to Install Magento 2 on XAMPP Server localhost.
Javascript(2)
ย 
PHP Summer Training Presentation
Principles of MVC for PHP Developers
Introduction to Browser Internals
Here Be Dragons - Debugging WordPress
Ad

Viewers also liked (15)

PDF
Magento 2 performance - a benchmark
ย 
PDF
White Paper - Magento 2.0 Performance and Scalability 03.31.16
PPT
CSS Fundamentals
ODP
JavaScript and jQuery Fundamentals
PPTX
Nodejs magento
ย 
ODP
Scaling and securing node.js apps
PDF
How to create theme in Magento 2 - Part 2
KEY
HTML CSS & Javascript
PPTX
Madison PHP - Getting Started with Magento 2
PDF
How To Create Theme in Magento 2 - Part 1
PDF
Improved Layered Navigation: Magento Extension by Amasty. User Guide.
ย 
PDF
Surprising failure factors when implementing eCommerce and Omnichannel eBusiness
ย 
PDF
Magento scalability from the trenches (Meet Magento Sweden 2016)
ย 
PDF
Omnichannel Customer Experience
ย 
PDF
Html / CSS Presentation
Magento 2 performance - a benchmark
ย 
White Paper - Magento 2.0 Performance and Scalability 03.31.16
CSS Fundamentals
JavaScript and jQuery Fundamentals
Nodejs magento
ย 
Scaling and securing node.js apps
How to create theme in Magento 2 - Part 2
HTML CSS & Javascript
Madison PHP - Getting Started with Magento 2
How To Create Theme in Magento 2 - Part 1
Improved Layered Navigation: Magento Extension by Amasty. User Guide.
ย 
Surprising failure factors when implementing eCommerce and Omnichannel eBusiness
ย 
Magento scalability from the trenches (Meet Magento Sweden 2016)
ย 
Omnichannel Customer Experience
ย 
Html / CSS Presentation
Ad

Similar to Less & RequireJS - Frontend Development in Magento 2 (17)

PDF
Nenad Andrakovic - Changing the way frontend developers think and work - Mage...
PDF
Introduction to Javascript in Magento 2 | Colorado Magento Meetup
PPTX
Mage Titans - Magento 2 Frontend Framework - UI Components
PDF
Magento2 Basics for Frontend Development
PPTX
MidwestPHP - Getting Started with Magento 2
PPTX
Magento2 what's new in theming
PPTX
Meet Magento Belarus 2015: Mladen Ristiฤ‡
ย 
PDF
Fronted From Scratch - Supercharge Magento page speed
PDF
Introduction to Magento 2 module development - PHP Antwerp Meetup 2017
KEY
Be German About Your Frontend
PPTX
#1HanoiMagentoMeetup_Magento 2 vs Magento 1
PPTX
Magento 2 development
PPTX
Magento mega menu extension
PDF
Irene Iaccio - Magento2 e RequireJS. The right way
PDF
Require js and Magento2
PDF
Javascript Frameworks for Joomla
PDF
Magento 2 Module in 50 Minutes
Nenad Andrakovic - Changing the way frontend developers think and work - Mage...
Introduction to Javascript in Magento 2 | Colorado Magento Meetup
Mage Titans - Magento 2 Frontend Framework - UI Components
Magento2 Basics for Frontend Development
MidwestPHP - Getting Started with Magento 2
Magento2 what's new in theming
Meet Magento Belarus 2015: Mladen Ristiฤ‡
ย 
Fronted From Scratch - Supercharge Magento page speed
Introduction to Magento 2 module development - PHP Antwerp Meetup 2017
Be German About Your Frontend
#1HanoiMagentoMeetup_Magento 2 vs Magento 1
Magento 2 development
Magento mega menu extension
Irene Iaccio - Magento2 e RequireJS. The right way
Require js and Magento2
Javascript Frameworks for Joomla
Magento 2 Module in 50 Minutes

Recently uploaded (20)

PDF
Cloud-Scale Log Monitoring _ Datadog.pdf
PDF
Decoding a Decade: 10 Years of Applied CTI Discipline
PPT
isotopes_sddsadsaadasdasdasdasdsa1213.ppt
PDF
๐Ÿ’ฐ ๐”๐Š๐“๐ˆ ๐Š๐„๐Œ๐„๐๐€๐๐†๐€๐ ๐Š๐ˆ๐๐„๐‘๐Ÿ’๐ƒ ๐‡๐€๐‘๐ˆ ๐ˆ๐๐ˆ ๐Ÿ๐ŸŽ๐Ÿ๐Ÿ“ ๐Ÿ’ฐ
ย 
PPTX
SAP Ariba Sourcing PPT for learning material
PDF
Automated vs Manual WooCommerce to Shopify Migration_ Pros & Cons.pdf
PDF
WebRTC in SignalWire - troubleshooting media negotiation
PDF
FINAL CALL-6th International Conference on Networks & IOT (NeTIOT 2025)
PDF
APNIC Update, presented at PHNOG 2025 by Shane Hermoso
ย 
PDF
Sims 4 Historia para lo sims 4 para jugar
PPTX
Digital Literacy And Online Safety on internet
PPTX
June-4-Sermon-Powerpoint.pptx USE THIS FOR YOUR MOTIVATION
PPT
Design_with_Watersergyerge45hrbgre4top (1).ppt
PPTX
Funds Management Learning Material for Beg
DOCX
Unit-3 cyber security network security of internet system
PDF
Slides PDF The World Game (s) Eco Economic Epochs.pdf
PPTX
international classification of diseases ICD-10 review PPT.pptx
PDF
Tenda Login Guide: Access Your Router in 5 Easy Steps
PDF
RPKI Status Update, presented by Makito Lay at IDNOG 10
ย 
PDF
Paper PDF World Game (s) Great Redesign.pdf
Cloud-Scale Log Monitoring _ Datadog.pdf
Decoding a Decade: 10 Years of Applied CTI Discipline
isotopes_sddsadsaadasdasdasdasdsa1213.ppt
๐Ÿ’ฐ ๐”๐Š๐“๐ˆ ๐Š๐„๐Œ๐„๐๐€๐๐†๐€๐ ๐Š๐ˆ๐๐„๐‘๐Ÿ’๐ƒ ๐‡๐€๐‘๐ˆ ๐ˆ๐๐ˆ ๐Ÿ๐ŸŽ๐Ÿ๐Ÿ“ ๐Ÿ’ฐ
ย 
SAP Ariba Sourcing PPT for learning material
Automated vs Manual WooCommerce to Shopify Migration_ Pros & Cons.pdf
WebRTC in SignalWire - troubleshooting media negotiation
FINAL CALL-6th International Conference on Networks & IOT (NeTIOT 2025)
APNIC Update, presented at PHNOG 2025 by Shane Hermoso
ย 
Sims 4 Historia para lo sims 4 para jugar
Digital Literacy And Online Safety on internet
June-4-Sermon-Powerpoint.pptx USE THIS FOR YOUR MOTIVATION
Design_with_Watersergyerge45hrbgre4top (1).ppt
Funds Management Learning Material for Beg
Unit-3 cyber security network security of internet system
Slides PDF The World Game (s) Eco Economic Epochs.pdf
international classification of diseases ICD-10 review PPT.pptx
Tenda Login Guide: Access Your Router in 5 Easy Steps
RPKI Status Update, presented by Makito Lay at IDNOG 10
ย 
Paper PDF World Game (s) Great Redesign.pdf

Less & RequireJS - Frontend Development in Magento 2