We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Template Layout question re stylesheets

How Do I?

Halogen's avatar
Halogen
74 posts
9 years ago
Halogen's avatar Halogen

Good afternoon!

I’ve just “discovered” and started playing with layouts. So far, I love them!

But I have one question: Some of my pages, include custom stylesheets:

<link href="{stylesheet='pet/style-form_contact.css}" media="screen" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">

I can’t quite seem to figure out how to get this into the layout. If I try and use a normal variable in the main layout tag, the quotes (single / double) appear to mosh up the output.

I’ve also had zero success with the dynamic layout variables either:

{layout:set name="color" value="red"}

Thoughts on how others include custom header info in their layouts….

       
Rob Allen's avatar
Rob Allen
2,950 posts
9 years ago
Rob Allen's avatar Rob Allen

Here’s a generic layout for you:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="{charset}">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{if layout:title != ''}{layout:title} - {/if}{site_name}</title>
<link rel="stylesheet" href="{stylesheet='inc/style'}">/* assumes your CSS template is in the 'inc' group and called 'style' */
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css"> 
</head>
<body>

Your global header HTML here

{layout:contents}

Your global footer HTML here

</body>
</html>

So calling the layout into another template you’d do:

Assuming your layout template is called _layout-general in the inc/ template group

{layout="inc/_layout-general"}
{layout:set name="title" value="My page title"}
       
Pedro Guimaraes's avatar
Pedro Guimaraes
170 posts
9 years ago
Pedro Guimaraes's avatar Pedro Guimaraes

In your template layout you’d have:

<html>
<head>
{layout:custom-css}
</head>
<body>
{layout:contents}
</body>

Then in a template where you want to use a custom stylesheet you’d set it like this:

{layout:set name="custom-css"}
<link rel="styesheet" href="custom.css">
<link rel="styesheet" href="custom2.css">
{/layout:set}
       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.