define a new css style sheet from within a weblog entry
Posted: 25 June 2009 02:01 PM   [ Ignore ]  
Summer Student
Avatar
Total Posts:  13
Joined  02-16-2009

Is it possible to have a variable in the <head> that can be defined from a weblog entry? I want to have a unique css style sheet design for every weblog entry. So when a single entry is being viewed the css for that entry will load in the head. When you go to the previous or next entries the respective css files will be loaded.

I have been looking for a solution for a while, please help!

Thank you!

Profile
 
 
Posted: 25 June 2009 02:35 PM   [ Ignore ]   [ # 1 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  130
Joined  09-17-2007

There are probably a few different ways to do this, but the first thought that came to my mind was to create a custom field in your weblog called “stylesheet” or something, and have that field display in the head of your template.

Then, you could either upload a new stylesheet each time (by making your custom field an upload field/the recipient of the upload’s location) or manually type in the location of your stylesheet if it’s on the server.

It’d be interesting to hear other solutions…

Profile
 
 
Posted: 25 June 2009 04:08 PM   [ Ignore ]   [ # 2 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  659
Joined  04-23-2006
daverod - 25 June 2009 02:01 PM

... I want to have a unique css style sheet design for every weblog entry ...

What exactly are you trying to achieve?


You want different font-family, background, color, text-decoration, etc.
I can think of one super simple method of doing this, but I’d like to test first, as this gives me some neat ideas smile

 Signature 

OLD username was jammo, NEW username is OrganizedFellow

It’s a struggle even to keep focused. This is the best of my AD/HD & GTD.
The exceptionally slow growth of my web dev projects is eclipsed by my patience, understanding and desire to learn AS MUCH AS POSSIBLE as I slowly progress.

Profile
 
 
Posted: 26 June 2009 07:50 AM   [ Ignore ]   [ # 3 ]  
Summer Student
Avatar
Total Posts:  13
Joined  02-16-2009
OrganizedFellow - 25 June 2009 04:08 PM

What exactly are you trying to achieve?

I am trying to make a personal site, somewhat of a design blog. Where each post is a new design, but there will be consistent elements so you know your on the same site. I got the idea from the brilliant http://jasonsantamaria.com/

I’m not trying to copy JSM (I don’t even think it’s possible), but I like the theory behind the site soo much that I have to try and see what I can do.

I’ll look into the custom field that updates in the head, I didn’t know that was possible. I havent been using EE for long oh oh

Profile
 
 
Posted: 26 June 2009 09:11 AM   [ Ignore ]   [ # 4 ]  
Summer Student
Avatar
Total Posts:  13
Joined  02-16-2009
ctrlaltdel - 25 June 2009 02:35 PM

... create a custom field in your weblog called “stylesheet” or something, and have that field display in the head of your template.

So I would use the weblog tag twice in the same template? Once in the head for the custom field and once for the content? and just have a limit of 1. That seems like a good solution. Thank You ctrlaltdel!

Profile
 
 
Posted: 26 June 2009 11:21 AM   [ Ignore ]   [ # 5 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  282
Joined  06-15-2008

Here’s how I do it for my EE sites:

1. Create a new template group called embeds and a new template within that group called header. The path to your header is now embeds/header.
2. Within your weblog template, replace your existing header area with the following tag:

{embed="embeds/header"}

3. Test your template to make sure the header is properly embedded (i.e., no broken layout or extra/missing div tags).
4. You can now pass in any variables you want. So, if you want to load a separate stylesheet, you can do something like this:

First, in your weblog template:

{embed="embeds/header" the_css_file="blue"}

Then, in your embeds/header template:

...doctype declaration, etc...
<
head>
    <
link rel="stylesheet" type="text/css" href="{stylesheet=home/style_{embed:the_css_file}}" />
    <
title>...</title>
</
head>

Here’s what’s happening:

- In your weblog template, when you call the embedded header template, you are also passing in the variable the_css_file (which you can name anything you want) and giving it a value of blue.
- In your embedded header template, the value you passed in from the weblog template (in this case, blue) is inserted. In the example above, the stylesheet home/style_blue would be loaded.

You may want to have a conditional that checks to see if an embedded variable is being passed; if not, load a default stylesheet. Something like this:

<link rel="stylesheet" type="text/css" href="{stylesheet=home/style_{if embed:the_css_file}{embed:the_css_file}{if:else}default{/if}}" />

I haven’t tested this, but it should work.

All that being said, I don’t think it’s a good idea to load a separate stylesheet for each weblog entry. What if you have dozens or hundreds of entries? That’s a lot of load on the server, even if the stylesheets are small. It’s quicker and better to load a master stylesheet, cache it once, and then use different CSS rules within your master stylesheet to control the display of each weblog entry.

To do this, you could follow the same steps above, but instead embed your variable in the <body> tag. Something like:

<body id="{embed:the_body_id}">

Then, within your CSS file, create different sets of rules to control how each weblog entry is displayed.

 Signature 

RYAN BURNEY • Lead Web Developer, 3 Roads Media
Denver based web and graphic design

Profile
 
 
Posted: 26 June 2009 12:56 PM   [ Ignore ]   [ # 6 ]  
Summer Student
Avatar
Total Posts:  13
Joined  02-16-2009

vosSavant - I am familiar with using variables in embedded templates, but then you have to set the variable within the embed tag. How would you define the variable from within a weblog entry? Otherwise you would need to have a separate template for each entry. Or is there something I’m missing. Can you dynamically set the variable?

Profile
 
 
Posted: 26 June 2009 02:14 PM   [ Ignore ]   [ # 7 ]  
Lab Assistant
RankRank
Total Posts:  270
Joined  09-28-2002

You could do something like this in the weblog template:

{if the_css_file != ''}
{embed
="embeds/_header" the_css_file ="{the_css_file}"}
{if
:else}
{embed
="embeds/_header"}
{
/if}

That should pass the CSS file as an embed variable if the custom field is not empty.

Then you could do something like this in the _header template:

<link rel="stylesheet" type="text/css" href="{stylesheet=home/style_default}" />
{if embed:the_css_file}
<link rel="stylesheet" type="text/css" href="{stylesheet=home/style_{embed:the_css_file}" />
{/if}

I’d use a common CSS file that contained most of the site design, and supplement it with entry-specific style sheets. They’d most likely be pretty small and wouldn’t add too much server load because they’d only be loaded on the pages that use them.

Profile
 
 
Posted: 26 June 2009 02:20 PM   [ Ignore ]   [ # 8 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  282
Joined  06-15-2008

Sorry daverod, I went off on a tangent.  red face 

I just noticed your reference to Jason Santa Maria’s website. I like that style, too. I’m not sure how JSM does it, but I would pass a unique ID to the single weblog entry page, then use the EE segment variable to determine what that ID is.

For example, in your parent page that lists all of your weblog entries:

{exp:weblog:entries weblog="css-madness"}
   
<li><a href="{path=detail/{weblog}/{weblog}_{entry_id}}">Read more of {title}</a></li>
{/exp:weblog:entries}

Then, in your detail view:

<body class="{segment_2}" id="{segment_3}">

Then, in your CSS:

.css-madness {
    
/* styles for ALL entries in the css-madness weblog */
    
}

#css-madness_234 {
    /* styles for a particular entry within the css-madness weblog */
    
}

Your segment variables may vary, but give this a shot - should be what you’re after.

 Signature 

RYAN BURNEY • Lead Web Developer, 3 Roads Media
Denver based web and graphic design

Profile
 
 
Posted: 29 June 2009 08:31 AM   [ Ignore ]   [ # 9 ]  
Summer Student
Avatar
Total Posts:  13
Joined  02-16-2009

Thanks for the help everyone. I think I will go with the solution of having a custom field where I can upload a new css file and link it in the head. Because I will only ever show one post at a time I should be able to open the weblog tag in the head and then close it later on in the body somewhere. I originally thought this was more complicated than it actually is, but EE makes it pretty easy.

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1743, on December 02, 2009 02:47 PM
Total Registered Members: 115019 Total Logged-in Users: 120
Total Topics: 122453 Total Anonymous Users: 71
Total Replies: 647339 Total Guests: 547
Total Posts: 769792    
Members ( View Memberlist )
Active Members:    .jb3000a38dAdam Dorseyadam.beaughAndrew MacphersonartsengineatiosisÑuño MartínezBen @PutYourLightsOnBennoboBlair Lbuckycatcc000001Chris ClarkeChris Warehamchrisbarber86Christian SchulteChristopher L. Jorgensencmw1Compass360cripcropCrucialD-RockdaithidapacreativeDavid RousseaudavidandlilaDavide BonettadesignerhandbagsdibejadstechroomdubsakdxagencyDylan Smith/ContextDesigneefalconErik Stainsbyexcematreatment53expocomfccinterForrest AndersonGeorgi VeznevgesturestudiogomacroGreg AkerguyrobertsGwarriorHrimthursiamnickIan CIngmar GreilITWYJacob RussellJenSkimjmorinjoemoJohn*JohnDJoobsjournalistoneKevin EvansKurt DeutscherlaurentPLaurie RuggleslebisolliquidbookLodewijklog cabinlorigoldbergLyle AndersonMarc MillerMario RodríguezMark BowenMark CroxtonMatt RichardsMatthew EllisMatthias HinrichsMattJeansmdesignneostructuralistNevin LyneNico SmitnimbleslickNoah Kuhnpab514PanchescoParisJCPascal KrietePeteWpMacedqbrandsregistryRenmanResponse1rippeRobb Ottenhoffrunning with scissorsrussliptonRyan FaubionSam SullivanscreentonicSean McDevittseansciarroneshinkasmartpillsmidoidSteven GrantstudionighTactile Design GroupTambour BattantThe Shotwell CompanytimprinttritcheytvruwinkvobtoaviX-Teamyabdabyo_danielzackmorgan