Play Youtube Video after click on Image

Step 1 : Open URL – http://www.tools4noobs.com/online_tools/youtube_xhtml/

Step 2 : Paste your YouTube URL, Set configuration and then Click on Generate Code button as per attached screenshot.
1

Step 3 : Now you will get your YouTube embed code. please review attached screenshot.
2

Step 4 : Pate below HTML code in your website :

<div onclick="thevid = document.getElementById('thevideo');
        thevid.style.display = 'block';
        this.style.display = 'none'"><img style="cursor: pointer;" src="capture.jpg" alt="" />
</div>
<div id="thevideo" style="display: none;">
    <object type="application/x-shockwave-flash" style="width:400px; height:225px;" data="http://www.youtube.com/v/mv1F_uBZRA4?color2=FBE9EC&amp;autoplay=1&amp;controls=0&amp;version=3&amp;modestbranding=1">
        <param name="movie" value="http://www.youtube.com/v/mv1F_uBZRA4?color2=FBE9EC&amp;autoplay=1&amp;controls=0&amp;version=3&amp;modestbranding=1" />
        <param name="allowFullScreen" value="true" />
        <param name="allowscriptaccess" value="always" />
    </object>
</div>

CSS3 link only triangle shape area

Use Below HTML code

<div class="actions">
    <a href="#" class="button btn-cart">
        <img src="images/demo.png">
    </button>
    <a href="#" class="product-detail">
        <img src="images/demo.png">
    </a>
</div>

Use Below CSS code


.actions {
    bottom: 0;
    height: 73px;
    overflow: hidden;
    position: absolute;
    right: 0;
    width: 74px;
}
.actions .button.btn-cart img, 
.actions .product-detail img, 
{
    height: 100%;
    transform-origin: inherit;
    width: 100%;
}
.actions .button.btn-cart {
    background: rgba(0, 0, 0, 0) none repeat scroll 0 0;
    left: 0;
    overflow: hidden;
    padding: 0;
    position: absolute;
    transform: skewX(1.02deg);
    transform-origin: 50% 0 0;
}
.actions .product-detail {
    background: rgba(0, 0, 0, 0) none repeat scroll 0 0;
    left: 0;
    overflow: hidden;
    padding: 0;
    position: absolute;
    transform: skewY(141.02deg);
    transform-origin: 100% 0 0;
}
.actions .product-detail img {
    transform: skewY(38.02deg);
}

sample

Display Static Block in PHTML and CMS Page in Magento 2

IN CMS PAGE FROM ADMIN :

{{block class="Magento\\Cms\\Block\\Block" block_id="block_identifier"}} 

IN PHTML FILE :

<?php echo $block->getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId('block_identifier')->toHtml();?>

IN XML FILE :

<referenceContainer name="content">
<block class="Magento\Cms\Block\Block" name="block_identifier">
<arguments>
<argument name="block_id" xsi:type="string">block_identifier</argument>
</arguments>
</block>
</referenceContainer>

Less Css Overview

Less is a CSS pre-processor, meaning that it extends the CSS language, adding features that allow variables, mixins, functions and many other techniques that allow you to make CSS that is more maintainable, themable and extendable.

Unlike regular CSS as we know it, LESS works much more like a programming language. It’s dynamic, so expect to find some terminologies like Variables, Operation and Scope along the way.

Variables :

The variables will allow us to store a constant value that later can be reused in the entire stylesheet.

Example :

@color-base: #2d5e8b;

.class1 {

background-color: @color-base;

}

.class2 {

background-color: #fff;

color: @color-base;

}

.class3 {

border: 1px solid @color-base;

}

Mixins:

In LESS, we can use Mixins to reuse whole declarations in a CSS rule set in another rule set. Here is an example:

.gradients {

background: #eaeaea;

background: linear-gradient(top, #eaeaea, #cccccc);

background: -o-linear-gradient(top, #eaeaea, #cccccc);

background: -ms-linear-gradient(top, #eaeaea, #cccccc);

background: -moz-linear-gradient(top, #eaeaea, #cccccc);

background: -webkit-linear-gradient(top, #eaeaea, #cccccc);

}

In the above snippet, we have preset a default gradient color inside the.gradients class. Whenever we want to add the gradients we simply insert the.gradients this way:

div {
.gradients;

border: 1px solid #555;

border-radius: 3px;
}

Mixins can also take arguments, which are variables passed to the block of selectors when it is mixed in.

For example:

.border-radius(@radius) {

-webkit-border-radius: @radius;

-moz-border-radius: @radius;

border-radius: @radius;

}

And here’s how we can mix it into various rulesets:

#header {

.border-radius(4px);

}

.button {

.border-radius(6px);

}


Parametric mixins can also have default values for their parameters:

.border-radius(@radius: 5px) {

-webkit-border-radius: @radius;

-moz-border-radius: @radius;

border-radius: @radius;

}

We can invoke it like this now:

#header {

.border-radius;

}

#footer { .border-radius(10px);}

You can also use parametric mixins which don’t take parameters. This is useful if you want to hide the ruleset from the CSS output, but want to include its properties in other rulesets:

.wrap() {

text-wrap: wrap;

white-space: -moz-pre-wrap;

white-space: pre-wrap;

word-wrap: break-word;

}

pre { .wrap }

Which would output:

pre {

text-wrap: wrap;

white-space: -moz-pre-wrap;

white-space: pre-wrap;

word-wrap: break-word;

}

Nested Rules :

In LESS CSS, we can simplify the rule sets by nesting the child elements inside the parents, as follows;

nav {

height: 40px;

width: 100%;

background: #455868;

border-bottom: 2px solid #283744;

li {

width: 600px;

height: 40px;

a {

color: #fff;

line-height: 40px;

text-shadow: 1px 1px 0px #283744;

}

}

}

You can also assign pseudo-classes, like :hover, to the selector using the ampersand (&) symbol.
Let’s say we want to add :hover to the anchor tag above, we can write it this way:

a {

color: #fff;

line-height: 40px;

text-shadow: 1px 1px 0px #283744;

&:hover {

background-color: #000;

color: #fff;

}

}

Operation :

We can also perform operations in LESS, such as addition, subtraction, multiplication and division to numbers, colors and variables in the stylesheet.

Let’s say we want element B to be two times higher than element A. In that case, we can write it this way:

@height: 100px

.element-A {

height: @height;

}

.element-B {

height: @height * 2;

}

Scope :
Scope in Less is very similar to that of programming languages. Variables and mixins are first looked for locally, and if they aren’t found, the compiler will look in the parent scope, and so on.

@var: red;

#page {

@var: white;

#header {

color: @var; // white

}

}

Importing :

Importing works pretty much as expected. You can import a .less file, and all the variables in it will be available. The extension is optionally specified for .less files.

@import “library”; // library.less

@import “typo.css”;

Lazy Loading :

Variables are lazy loaded and do not have to be declared before being used.

Valid Less snippet:

.lazy-eval {

width: @var;

}

@var: @a;

@a: 9%;

Loading jQuery in .noConflict() Mode With RequireJS In Magento 2

Step – 1

Download jQuery which version you want.For example i am taking jquery-1.9.1.min.js
Now put it on “Namespace/Module/view/frontend/web/js” path

Step – 2

create new js file which name is “jquery.no-conflict.js” on “Namespace/Module/view/frontend/web/js” path
copy and paste below code in to it

1
2
3
4
define(['jQuery191'],function ()
{
    return jQuery.noConflict(true);
});

Step – 3

create “requirejs-config.js” file on “Namespace/Module/view/frontend/” path
copy and paste below code in to it

1
2
3
4
5
6
7
var config = {
"paths":
{
    "jQuery191": "Demo_Welcome/js/jquery-1.9.1.min",
    "jqueryNoConflict": "Demo_Welcome/js/jquery.no-conflict",
}
};

Step – 4

Open any .phtml file form “Namespace/Module/view/frontend/templates” path and copy and paste below code in it

1
2
3
4
5
6
7
8
9
10
"text/javascript" language="javascript">
    require(["jqueryNoConflict"],function(jQuery)
    {
        (function ($)
        {
             var version = $().jquery;
             alert(version);
        })(jQuery);
    });

RequireJS In Magento2 (Basics)

What is RequireJS

  • RequireJS is a JavaScript Framework and module loader.  It means we have to follow RequireJS standards in order to implement JS/jQuery in Magento2. RequireJS loads plain JavaScript files as well as more defined modules. RequireJS improves the speed and quality of your code by breaking large appication into smaller manageable code.
  • Developed By RequireJS.org
  • RequireJS Version In Magento2 : 2.1.11
  • RequireJS Current Version : 2.1.20

 

Benifits of RequireJS

  • It’s as few HTTP requests are required.
  • The code order doesn’t matter
  • Asynchronous JavaScript loading
  • The file is easy to understand
  • RequireJS can tie them together at compile time
  • RequireJS only loads the JS script that the page needs.

In Magento2, There are two mandatory JS.

  1. require.js
  2. requirejs-config.js
  • Path & Script to include require.js
    app\code\Magento\Theme\view\frontend\layout\default_head_blocks.xml
    <script src=”requirejs/require.js”/>
  • requirejs-config.js is used for mapping js, defining dependencies, defining paths etc.

JS resources can be specified at several levels

  • At the library level (lib/web)
  • At the module level (app/code/{Namespace}/{Module}/view/{area}/web)
  • At the theme module level (app/design/{area}/{Vendor}/{theme}/{Namespace}_{Module}/web)
  • At the theme level for all libraries(app/design/{area}/{Vendor}/{theme}/web).

 

Example : To use custom Js in custom Module

  • Custom Module : Newspace_Hello
  • Custom Js : app/code/Newspace/Hello/view/frontend/web/js/myjs.js
  • Put below code into your template file
  • 1
    2
    3
    require (['Newspace_Hello/js/myjs'], function(myjs) {
    myjs.output ('V Good');
    });

 

Mapping of JS files with particular Variable

  • Path For ‘requirejs-config.js’ File: app/code/{Namespace}/{Module}/view/{area}/requirejs-config.js
  • Below is example that how to map js in requirejs-config.js:
    1
    2
    3
    4
    5
    6
    7
    8
    var config = {
    map: {
    '*': {
    crsl: 'Newspace_Hello/js/crsl,
    jquery_191: 'Newspace_Hello/js/jquery_191'
    }
    }
    };

 

Define Dependency

  • To build a dependency on the third-party plugin, specify a shim in the following configuration file: requirejs-config.js
    1
    2
    3
    4
    5
    6
    7
    var config = {
    "shim": {
    'crsl': {
    deps: ['jquery_191']
    }
    }
    };
  • If newer OR older jQuery version require
    1
    2
    3
    require (['jquery_191','crsl'], function(jquery_191) {
    // Do you code with jquery_191 object
    });

Responsible Magento module to compile JS

  • app/code/Magento/RequireJs

 

Path of JS files before compilation

  • requirejs.js : lib/web/requirejs/ requirejs.js
  • Other Js Files : In their relevant modules OR lib OR theme.

 

Path of JS files after compilation

  • requirejs.js : pub/static/frontend/Magento/blank/en_US/requirejs.js
  • requirejs-config.js : _requirejs/frontend/Magento/blank/en_US/requirejs-config.js
  • Module JS Files : pub/static/frontend/Magento/blank/en_US/{Namespace}_{ModuleName}/js
  • Other Js Files : pub/static/frontend/Magento/blank/en_US

 

Find loaded JS files in browsers

  • Google Chrome : ‘Network’ Tab in Developer Tools
  • Mozilla Firefox : ‘Net’ Tab in Developer Tools

Less Compilation using Grunt in Magento2 for Windows Users

After Successfully Installing Grunt in Your Project follow the below process :-

1. Add your theme to Grunt configuration. To do this, in the dev/tools/grunt/configs/theme.js file, add your theme to module.exports like following:

module.exports = {
     <theme>: {
         area: 'frontend',
         name: '<Vendor>/<theme>',
         locale: '<language>',
         files: [
             '<path_to_file1>', //path to root source file
             '<path_to_file2>'
        ],
     dsl: 'less'
 },

2. Run cmd as Administrator
3. Go to your root directory of your Project using cmd
4. Run below command :-
grunt exec:<theme>
5. after that Run this command :-
grunt watch
6. Now make changes in your Less file.
example: _theme.less
7. Refresh browser and see the changes.

Note :You can also use livereload to see changes without refreshing the browser.

Patches for Master branch users. Kindly follow below link and apply the appropriate change in your code to run grunt watch:


Index: magento2ce/lib/internal/Magento/Framework/Less/PreProcessor/Instruction/Import.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
— magento2ce/lib/internal/Magento/Framework/Less/PreProcessor/Instruction/Import.php (revision )
+++ magento2ce/lib/internal/Magento/Framework/Less/PreProcessor/Instruction/Import.php (revision )
@@ -51,7 +51,12 @@
return $this->replace($matchContent, $asset);
};
$content = $this->removeComments($chain->getContent());
– $chain->setContent(preg_replace_callback(self::REPLACE_PATTERN, $replaceCallback, $content));
+
+ $processedContent = preg_replace_callback(self::REPLACE_PATTERN, $replaceCallback, $content);
+
+ if ($processedContent !== $content) {
+ $chain->setContent($processedContent);
+ }
}
/**
Index: magento2ce/app/code/Magento/Developer/Test/Unit/Console/Command/CssDeployCommandTest.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
— magento2ce/app/code/Magento/Developer/Test/Unit/Console/Command/CssDeployCommandTest.php (revision )
+++ magento2ce/app/code/Magento/Developer/Test/Unit/Console/Command/CssDeployCommandTest.php (revision )
@@ -113,6 +113,8 @@
->method('create')
->with('less')
->willReturn($this->getMock('Magento\Framework\Less\FileGenerator', [], [], '', false));
+ $asset = $this->getMockForAbstractClass('Magento\Framework\View\Asset\LocalInterface');
+ $asset->expects($this->once())->method('getContentType')->willReturn('type');
$this->assetRepo->expects($this->once())
->method('createAsset')
->with(
@@ -123,9 +125,7 @@
'locale' => 'en_US'
]
)
– ->willReturn(
– $this->getMockForAbstractClass('Magento\Framework\View\Asset\LocalInterface')
– );
+ ->willReturn($asset);
$this->assetSource->expects($this->once())->method('findSource')->willReturn('/dev/null');
$this->chainFactory->expects($this->once())->method('create')->willReturn(
Index: magento2ce/app/code/Magento/Developer/Console/Command/CssDeployCommand.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
— magento2ce/app/code/Magento/Developer/Console/Command/CssDeployCommand.php (revision )
+++ magento2ce/app/code/Magento/Developer/Console/Command/CssDeployCommand.php (revision )
@@ -219,21 +219,23 @@
]
);
+ $rootDir = $this->filesystem->getDirectoryWrite(DirectoryList::ROOT);
$sourceFile = $this->assetSource->findSource($asset);
– $content = \file_get_contents($sourceFile);
+ $relativePath = $rootDir->getRelativePath($sourceFile);
+ $content = $rootDir->readFile($relativePath);
$chain = $this->chainFactory->create(
[
'asset' => $asset,
'origContent' => $content,
– 'origContentType' => $asset->getContentType()
+ 'origContentType' => $asset->getContentType(),
+ 'origAssetPath' => $relativePath
]
);
$processedCoreFile = $sourceFileGenerator->generateFileTree($chain);
$targetDir = $this->filesystem->getDirectoryWrite(DirectoryList::STATIC_VIEW);
– $rootDir = $this->filesystem->getDirectoryWrite(DirectoryList::ROOT);
$source = $rootDir->getRelativePath($processedCoreFile);
$destination = $asset->getPath();
$rootDir->copyFile($source, $destination, $targetDir);

Installing and configuring Grunt in Magento 2

Magento has built-in Grunt tasks configured, but there are still several prerequisite steps you need to take to be able to use it:

  1. Install node.js to any location on your machine.
  2. Install Grunt CLI tool globally. To do this, run the following command in a command prompt:
npm install -g grunt-cli
  1. Install Grunt in your Magento directory. To do this, run the following commands in a command prompt:
cd <your_Magento_instance_directory>
npm install grunt --save-dev
  1. Install (or refresh) the node.js project dependency for your Magento instance. To do this, run the following commands in a command prompt:
cd <your_Magento_instance_directory>
npm install
npm update
  1. Add your theme to Grunt configuration. To do this, in the dev/tools/grunt/configs/theme.js file, add your theme to module.exports like following:
module.exports = {
    <theme>: {
        area: 'frontend',
        name: '<Vendor>/<theme>',
        locale: '<language>', 
        files: [
            '<path_to_file1>', //path to root source file
            '<path_to_file2>'
        ],
    dsl: 'less'
    },

Where the following notation is used:

<theme>: your theme code, conventionally should correspond to the theme directory name.

<language>: specified in the ‘code_subtag’ format, for example en_US. Only one locale can be specified here. To debug the theme with another locale, create one more theme declaration, having specified another value for language

<path_to_file>: path to the root source file, relative to the app/design/frontend/<Vendor>/<theme/>webdirectory. You need to specify all root source files of the theme. If your theme inherits from a certain theme, and does not contain its own root source files, specify the root source files of the parent theme.

  1. (Optional) If you want to use Grunt for “watching” changes automatically, without reloading pages in a browser each time, install the LiveReload extension in your browser.

Grunt commands

The following table describes the grunt commands you can use performing different customization tasks. Run all commands from your Magento installation directory.

Grunt task Action
grunt clean:<theme>

For example:

grunt clean:blank
Removes the theme related static files in the pub/static and var directories.
grunt exec:<theme>
Republishes symlinks to the source files to the pub/static/frontend/<Vendor>/<theme>/<locale> directory.
grunt less:<theme>
Compiles .css files using the symlinks published in the pub/static/frontend/<Vendor>/<theme>/<locale> directory
grunt watch
Tracks the changes in the source files, recompiles .css files, and reloads the page in the browser pages (you need to have LiveReload installed for you browser)

Dynamic CSS Sprites Using Saas and Compass in Magento 1.9

Step 1: Create a folder inside the images folder and rename it to icons

Step 2: Add some images in icons folder

Step 3: Now go to the SCSS folder and Add below code in _framework.scss

// configuration variables
$icons-sprite-dimensions:true;

// required for basic spriting
@import “compass/utilities/sprites”;
@import “../images/icons/*.png”;

/* Compass mixin for displaying the custom classes.
* Make sure to commenting out the all-icons-sprites mixin, otherwise you’ll have duplicated classes.
* .creator {
* @include icons-sprite( your_image_name);
* }
*/

Step 4: Don’t forget to check RELATIVE ASSETS in config.rb it must be true if not than Add below line on that.

# To enable relative paths to assets via compass helper functions. Uncomment:
relative_assets = true

Step 5:Complie SCSS folder & files

.classname {@include icons-sprite( your_image_name);}

Step 6: Now you are ready to Use Dynamic Sprites Just use below code

Example:
.facebook-icon {@include icons-sprite(facebook);}

<div><span class=”facebook-icon”>&nbsp;</span>Facebook</div>

Setup Grunt in Minutes

Step 1 : – Download and Install NodeJs from its official Website https://nodejs.org/ according to your Operating System i.e (Windows , Linux)

Step 2 : – Now open Command Prompt (cmd)

Step 3 : – Once you have Node install properly you simply run:

npm install -g grunt-cli

This installs the Grunt command line interface globally to your machine so that you can access it. Continue reading Setup Grunt in Minutes