What is the best way to order a CSS file of a custom theme at the bottom of in Magento 2. By example, I would like place CSS after or before an other.
Thanks
Unfortunately there is no way to position your CSS files. You can however add the media attribute to the css element. This will add it to the end of all the included CSS in the head.
<head>
<css src="css/styles.css" media="all" />
</head>
Related
Is it possible to do this in AsciiDoc? I tried to stylize it using bootstrap CSS:
:stylesheet:
https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css
The attribute :stylesheet: works with local files only.
You can write a local CSS style.css and then include it in your doc.adoc like this.
// style.css
#import "https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css";
// doc.adoc
:stylesheet: style.css
To make the result look pretty, you'll still need to write more CSS to match the classes the Asciidoctor HTML output uses.
The following page might help you: https://asciidoctor.org/docs/produce-custom-themes-using-asciidoctor-stylesheet-factory/
As I just learned from https://stackoverflow.com/a/29456923/200509 , asciidoc has a passthrough block functionality which allows to insert snippets of raw HTML, i.e. CSS or JS code or references, into the rendered output.
Accordingly, putting this somewhere in your .adoc file should work:
++++
<link rel="stylesheet" type="text/css" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
++++
I'm using a Laravel app with an external public directory, e.g. root/Laravel, and root/html/public.
I need this app to load from a require on an php file that already has another framework(root/html/this-section.php), hence that other fw has its own head, and body tag. This app will load between the header and footer of that index.
In my blade layout.app file, i have
#section('stylesheets')
<link rel="stylesheet" href="/this-section/css/vendors.css">
<link rel="stylesheet" href="/this-section/css/app.css">
#show
<div id="main">
#include('layouts.sidebar')
#include('layouts.header')
<section>
#yield('content')
</section>
</div>
The issue I'm having is if no my app layout, when I delete the head and body tags during testing, which is what i need, the blade system, or what i dont know, is still creating an empty head tag set, <head></head>, then when i enable the stylesheets section, it ends up in that <head> tag.
Expected: The head tag should not be there. I don't want a head tag. What in laravel can i adjust to remove this auto creation of head (and body)?
It sounds like your using tags that belong in the <head> section is causing this. While your source may be pristine:
browsers will add in the missing-but-required tags as appropriate, resulting in you seeing them in the browser's web inspector:
I've got specific Form component, which is declared as
Form::component('fcRadio', 'components.form.fcradio', ['name', 'options', 'selected' => null]);
and used as
{{ Form::fcRadio('name', $options }}
What I want is somehow attach custom CSS file, so if the page fires this component at least once, the desired CSS file is included to the <head> of my document.
For example, in Joomla it was like
$this->document->addStylesheet('my_awesome_style.css');
Is there any way to achieve the same in Laravel?
UPD:
I've extended the answers below a bit to let it add multiple styles from multiple templates. Finally, it looks like this:
#section('styles')
#parent
{{HTML::style('css/fcradio.css')}}
#stop
It works fine, but if I use the component twice per page, style is also adds twice. How can I allow multiple but unique entries?
So this is typically how I deal with it:
In your folder: resources/views I create a folder called layout. This folder handles the templates for all my pages.
Then I create a file called default.blade.php. In it I put the bulk of the HTML code. Here's an example of how default.blade.php could look (slimmed down, obviously)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>
#yield('title')
</title>
<link rel="stylesheet" href="{{ asset('css/main.css') }}">
<!-- Additional per-page css -->
#yield('css')
</head>
<body>
#yield('content')
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="js/script.js"></script>
<script src="{{ asset('js/bootstrap.min.js') }}"></script>
<!-- Include per-page JS -->
#yield('js')
</body>
</html>
Right, so essentially what we have so far is the #yield() and asset() helpers.
#yield() is special blade syntax that Laravel uses to say, "Okay. Any time a blade view that is inheriting THIS master template calls the section named in this #yield() I will display that content right here.
asset() is a nifty little helper that basically appends your URL structure onto the string you pass it. So if your url is http://MyGreatSite.com and you use asset('js/script.js') it will spit out a fully qualified URL that will work anywhere on the site (http://MyGreatSite.com/js/script.js). asset() is great because you can use it in blade templates that will get sent out as an email and all of the files will work in an email inbox because they are absolute links.
Right. So now we have this master template and we need to use it. So what I do is create another view in the resources/views directory. Lets say we're doing a contact page. I would make contact.blade.php. Now I want to inherit that master template we created. So we do that like so:
#extends('layout.default)
#section('css')
<link rel="stylesheet" href="{{ asset('css/contact.css') }}">
#stop
#section('title')
Contact Us
#stop
#section('content')
<h1>Contact us</h1>
<p>
Contact us via email: contact#mygreatsite.com
</p>
#stop
#section('js')
<script src="{{ asset('js/contact-form.js') }}"></script>
#stop
Okay, so, first things first. At the very top we tell this blade file that we want to use the template we just made. We use the blade helper #extends() and pass it the path to our view relative to the views directory separated by periods.
Next, we want to create the sections that correspond to the template. We do that by opening the section with #section() and passing the name of the section we want to push this block of content to. We write our content and then we close the section by using #stop. Pretty simple. For images, css, or js, we simply use the asset() helper again.
I know it's a little long-winded, but hopefully that helps and explains the process a little better.
tl;dr: Use #yield(), #section(), and asset().
So I think I understand what you are saying.
In your blade layout file create a section inside the head:
<head>
#yield('componentcss')
</head>
And in the component do:
#section('componentcss')
{{HTML::style('css/fcradio.css')}}
#stop
You could also just include the css but I wouldn't advise this:
#section('componentcss')
<style>
.exampleclass {text-align:center;}
</style>
#stop
Hopefully I have understood you correctly.
I've finally found a bit tricky but working solution:
#hasSection('fcRadioStyle')
#else
#section('fcRadioStyle')
{{Html::style('css/components/fcradio.css')}}
#stop
#section('styles')
#yield('fcRadioStyle')
#append
#endif
This makes by Form::fcRadio append this style only once
I have a site with a fairly complex structure of Smarty templates. For this question, suppose I have an outer template which includes (with {include}) one or more inner templates that are optionally included, depending on the data being displayed:
Outer Template (with <html>, <head>, and <body> tags)
- Inner Template A (various content)
- Inner Template B (more content)
Sometimes, one of these inner templates needs to reference additional CSS files. I would prefer to have these within my <head> tag, for efficiency and to avoid FOUC. Is it possible to set some variable from Inner Template A that adds the appropriate <link> tag to <head> within Outer Template?
I was able to find someone who created a module to do something similar, but I don't know how I would set the necessary variables from the template to make it work in my case. I am using Smarty 3.
I had a similar issue some time ago. My solution is maybe dirty but maybe it could help you.
$css = '<link rel="stylesheet" type="text/css" href="/css/file.css">';
$smarty->registerFilter('output',create_function('$output','return preg_replace(\'/(<\/head>)/i\',\''.$css.'$1\',$output,1);'));
If you wrap this in a function, you can simply add css to your head section from everywhere.
Idea 1:
Wrap the same logic around the style sheet in your head that you use for displaying template A or B.
Idea 2:
Template 1 (Top Level):
<link rel="stylesheet" type="text/css" href="whatevs1">
{block name="childStyles"}
{/block}
Template 2 (Child Template):
{block name="childStyles"}
<link rel="stylesheet" type="text/css" href="whatevs2">
{/block}
A side note:
I understand the want to be W3 compliant using includes for stylesheets in HEAD but including them within the body wont break your html, even in IE7...
I encountered a similar obstacle a few years ago. Since smarty templates are almost all the time filled with php code, my solution is just declaring a special variable/array for this purpose in php, then looping through the array in your head template / outer template.
Example:
$your_special_css = array('css1.css', 'css2.css');
Somewhere else in your code...
$your_special_css[] = 'css3.css';
...and then give it to the template:
$your_smarty_template->assign('your_css', $your_special_css);
Then your outer template would look like this:
<head>
...
{foreach $your_css as $css}
<link rel="stylesheet" type="text/css" href="/css/{$css}">
{/foreach}
...
</head>
Same works for jscript-files, too.
Suppose a site is very configurable, and it has a few orthogonal settings which are all easily controlled with alternate stylesheets. For example, its main menu can be at the top or on the left, and its background colour can be red or blue.
Is there a way to define multiple sets of alternate stylesheets so that we can replace the 'theme' for each set?
I'm looking for something like this:
<link rel="stylesheet" set="background" title="red" />
<link rel="alternate stylesheet" set="background" title="blue" />
<link rel="stylesheet" set="main-menu" title="left" />
<link rel="alternate stylesheet" set="main-menu" title="top" />
No you can't do that. The three ways are:
Have a set of sheets on the server, and serve the correct one
Use inline CSS
Combination of both. Load all unchangable classes in an external CSS, then use an inline style sheet to set the customisable values.