3

Trying to have a style sheet only used when the user is not on the home screen. This code in my head section should work, correct?

{if embed:loc != "home"}
<style> body {background:url(images/interface/header_bg_slice3.png) repeat-x,    
url(images/interface/texture_bg.png) top left, repeat;}</style>
{/if}   

here is the corresponding code I'm using in the page template:

{embed="embeds/html_header" page_title="About Us" loc="about-us"}

what am I missing?

2
  • 1
    Yes, that is correct, you are not missing anything. Is it not working for you when you inspect the source code of your page? Commented Dec 27, 2012 at 23:09
  • This should be working. Have you tried {if "{embed:loc}" != "home"}? Does {embed:loc} output what you expect if you print the variable outside the conditional just to check?
    – Kevin Cupp
    Commented Dec 28, 2012 at 15:56

3 Answers 3

4

Another option would be to avoid using embedded styles and add a class to your body tag based on what page is loaded. Then you can adjust your body background in your stylesheet instead of the templates.

Like vfalconi said, you can often base this off the index not having a segment:

<body{if segment_1} class="subpage"{/if}>

Then in your stylesheet:

.subpage { your styles here... }
0
3

Have you tried:

{if segment_1}...{/if}

In most cases, if the user is on the site index, there wouldn't be a segment_1. Just seems a much more straight-forward approach to what you're trying to achieve (from what I can tell).

1

Similar to what Jim said but this would give a bit more flexibility:

{embed="embeds/_html_head" body_id="your-css-id" body_class="your-css-class"}

and then within that embed

<body id="{embed:body_id}" class="{embed:body_class}">

You can also achieve the same thing with Low Vars (less overhead too)

{exp:low_variables:single
var='lv_html_head'
preparse:body_id='home'
preparse:page_title='Home'
}

where lv_html_head is a textarea Low Variable containing what would be in your embed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.