Magento 2 custom css file include - magento

I am new in Magento and using the current version of Magento ie. 2.2.0.
I have my custom css file which I need to call in the website but the problem is that I don't know where to keep that css file or how to call that file.
Where do I place the css, and how do I use it?

The documentation is able to answer that. See here: http://devdocs.magento.com/guides/v2.0/frontend-dev-guide/css-topics/css-themes.html.
Here's an excerpt from it:
The recommended way to do this is adding an extending
default_head_blocks.xml in your theme, and including the required
stylesheets in this file.
Your custom default_head_blocks.xml should be located as follows:
<theme_dir>/Magento_Theme/layout/default_head_blocks.xml. To include a
CSS file, add the <css src="<path>/<file>" media="print|<option>"/>
block in <head> section in a layout file. <path> is specified relative
to the theme web directory (/web) For example, the
following illustrates how stylesheets are included in the default
Blank theme:
<Magento_Blank_theme_dir>/Magento_Theme/layout/default_head_blocks.xml
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<css src="css/styles-m.css" />
<css src="css/styles-l.css" media="screen and (min-width: 768px)"/>
<css src="css/print.css" media="print" />
</head>
</page>
If you are using the Luma theme, you could edit it directly, but it's best to create your own theme that extends it and add the css there. See here: http://devdocs.magento.com/guides/v2.0/frontend-dev-guide/themes/theme-create.html.

Related

How to exclude css to load from homepage alone in magento 2?

I want to add if condition in layout xml file to allow css to load in below scenarios.
To load css file only in home page alone.
To load css by devices(Desktop, mobile & tab)?
Please let me know how to add condition in layout xml file?
<head>
<css src="fonts/Lato/lato.css" /> <!-- Should be loaded in website home page only -->
<css src="css/styles-mobile.css"/> <!-- Should be loaded in mobile devices only -->
</head>
To load css file only on home page you need to do this things.
You can add below code in you custom theme
app\design\frontend\<vendor>\<theme>\Magento_Theme\layout\cms_index_index.xml
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<css src="fonts/Lato/lato.css"/>
</head>
<body>
</body>
</page>
And add lato.css into app\design\frontend\<vendor>\<theme>\web\css\fonts\Lato.

Magento 2 override default.phtml and items.phtml in new order email

I made a module that overrides default.phtml and i put and product image in there, and it works fine!
I made this sales_email_orders_renderers.xml to overide the default.phtml
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="sales.email.order.renderers">
<block class="Magento\Sales\Block\Order\Email\Items\Order\DefaultOrder" as="default" template="EmizenTech_SalesEmail::email/items/order/default.phtml"/>
</referenceBlock>
</body>
</page>
The original is in vendor/magento/module-sales/view/frontend/templates/email/items/order/
But how to also override the items.phtml in an other folder?
/vendor/magento/module-sales/view/frontend/templates/email/
Do i need to make an other xml or can i put some tags in the existing one?
Please go to your theme and create folder
Magento_Sales/templates/email/items/order
then
download default.phtml file
from
/vendor/magento/module-sales/view/frontend/templates/email/items/order
then paste here
Magento_Sales/templates/email/items/order your theme.

Including page layout to Laravel project

I was supplied with a custom layout for the login page of my Laravel project.
When I opened login.html file, which represents the layout for that specific page I saw such links
<!-- Base Css Files -->
<link href="assets/libs/jqueryui/ui-lightness/jquery-ui-1.10.4.custom.min.css" rel="stylesheet" />
<link href="assets/libs/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
<link href="assets/libs/font-awesome/css/font-awesome.min.css" rel="stylesheet" />
...
So I figured that I only need to copy the assets folder, which came with the template (there are all needed bootstraps, jqueries and whatnot) to my projects app\resources\assets directory
Now, when I copied the code from login.html into my login.blade.php view and copied the templates' assets folder to app\resources\assets it doesnt work. It only displays naked html code when I open the page.
What am I doing wrong in linking the assets folder?
The resources folder is (like the name says) for the resources.
If you don't want/need to build/compile/min your scripts, then just put them in the public folder, so you can access them from your template.
In your case
public/assets/libs...
In order to access assets, you have two ways to approach it. Either using Elixir/gulp or to use direct access.
Gulp is a node.js application that reads your assets files, whether JS, CSS, Coffee, etc...and combine them in single files. Gulp reads the files defined in the gulpfile.js, and you can access the output files in your blade file using elixir().
You can read more about Elixir here.
In your specific case, you can just place the files under the public/ directory. So Laravel treats public as the root directory, and if you want to read the file assets/css/foo.css just place the file in public/assets/css/foo.css

Using Virtual Paths in ASP.NET MVC 3

I have a layout page which is shared across all of the views in my app. That view references the .css in my app. For the sake of reference, I currently have the following at the top of my _layout.cshtml file:
<link rel="stylesheet" href="/css/themes/default/app.css" />
I am planning on taking this app and loading into a phone app via PhoneGap. Because of that, I cannot use /css/themes/default.app.css. Instead, I need to get it converted to a string that is relative to the path of the file. For instance, I need to dynamically generate a value that looks something like the following:
<link rel="stylesheet" href="../../../css/themes/default/app.css" />
The number of "../" will be determined based on how deep it is. I figured there would be a utility or something built into the ASP.NET MVC 3 framework to do this. However, I can't find anything. I have a LOT of files and I don't want to have to manually update all of the url patterns. Is there a utility that will automatically handle what I'm trying to acomplish? If so, how?
Thank you
Use the UrlHelper.Content HTML Helper method .
This method Converts a virtual (relative) path to an application absolute path.
<link href="#Url.Content("~/css/themes/default/app.css")"
rel="stylesheet" type="text/css" />
You may drop your css folder under the Content directory in the root of your MVC project

Joomla - Insert .js and .css files into a single Joomla article?

Is it possible for a single page on a Joomla website to include it's own custom .js and .css files?
I basically would like to add two custom javascript and css files for a particular page. I don't want these files included into any other Joomla pages.
Any suggestions would be appreciated.
Thank you
Try using a custom code extension such as JUMI. It is designed exactly for this purpose.
From the description: With Jumi you can include php, html, javascript scripts into the modules position, articles, category or section descriptions, or into your own custom made component pages.
The solution from Soygul wont result in proper HTML since these statements / includes belong to the HTML header.
Use : http://extensions.joomla.org/extensions/edition/custom-code-in-modules/11936
This plugin allows inserting material into the head section of your Joomla web site.
You can then use the menu assignment functionality to just add that to certain pages.
Its quite easy to write a simple module like that for yourself - but since this seems already available go with that one. If it doesn't fit your needs :
You just need an "empty / hello world" module with these two statements :
( http://docs.joomla.org/Creating_a_Hello_World_Module_for_Joomla_1.5 )
( http://docs.joomla.org/Adding_JavaScript_and_CSS_to_the_page )
// Add a reference to a Javascript file
// The default path is 'media/system/js/'
JHTML::script($filename, $path, $mootools);
// Add a reference to a CSS file
// The default path is 'media/system/css/'
JHTML::stylesheet($filename, $path);
I'm not a big fan of adding new extensions to Joomla unless absolutely necessary. If you do, make sure it's not on Joomla's list of vulnerable extensions, first. Each third-party extension/plugin you add is just one more potential back door for hackers.
To add your own custom CSS for a page, you can either edit your template's master CSS file, or just create your own and link it to the project. Here's how you'd do that:
First, figure out how your CSS files are being called. The actual file names will surely differ from my example, based upon the template you're using, but let's look at the Joomla SYSTEM template, which is located in templates/system. The index.php file controls everything, so open it up and you'll find this line:
<?php
include dirname(__FILE__).DIRECTORY_SEPARATOR.'component.php';
?>
Open component.php and you'll see some code that looks like this:
<head>
<jdoc:include type="head" />
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/system/css/general.css" type="text/css" />
You can see the call to include a CSS file in the 3rd line. All you need to do is add another line calling a CSS file you create. Create a new file called /templates/system/css/custom.css (or whatever you like) and rewrite the code segment in component.php to look like this:
<head>
<jdoc:include type="head" />
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/system/css/general.css" type="text/css" />
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/system/css/custom.css" type="text/css" />
Now you can just code out your own CSS in the new custom.css file you created. You can do this with any template system from RocketTheme or YooTheme just as easily. In fact, if you use one of their templates, they probably already have a custom.css file that you can simply add your own code to. Just be aware if you do it that way and then later update the template, you'll lose your code additions. That's why I prefer writing my own file. You can probably do something very similar to include custom JS code, but I tend to avoid JS like the plague, so someone else will have to address how to link out to a custom JS file.

Resources