• twitter image
  • facebook image
  • youtube image
  • linkedin image
Language: CMS Made Simple Czech CMS Made Simple France CMS Made Simple Spain CMS Made Simple Hungary CMS Made Simple Russia CMS Made Simple Netherlands

All times are UTC




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: How to add a class to body tag
PostPosted: Thu Apr 07, 2011 8:57 pm 
Offline
Forum Members
Forum Members

Joined: Thu Sep 16, 2010 11:56 pm
Posts: 44
I'm not sure if this is the correct forum. Please excuse me if it isn't.

The way our CMS was set up was with 5 different templates. The only difference between the templates is that the body tag has a different background image for each template in a css class.

Is there a way to do this without having a separate template for each instance the background image changes?

Thank you very much,
Camille


Top
 Profile  
 
 Post subject: Re: How to add a class to body tag
PostPosted: Thu Apr 07, 2011 10:31 pm 
Offline
Power Poster
Power Poster
User avatar

Joined: Tue Dec 23, 2008 8:39 pm
Posts: 1321
Remove the background-image from the stylesheet and use inline styles instead. Rename the images to match the page-alias that you are on or other such scheme.

Template:
Code:
<body style="background-image:url({$page_alias}.jpg);">

Change the page, you get a different picture. If you share the same picture for several pages, you can make a one-liner content box where the content editor can type in the name of the image they want. If they don't enter one in, your template logic would use a default image.


Top
 Profile  
 
 Post subject: Re: How to add a class to body tag
PostPosted: Fri Apr 08, 2011 12:06 am 
Offline
Forum Members
Forum Members

Joined: Thu Sep 16, 2010 11:56 pm
Posts: 44
Thank you! I will work on that tonight. How do I create a one-liner content box though?

Thanks!


Top
 Profile  
 
 Post subject: Re: How to add a class to body tag
PostPosted: Fri Apr 08, 2011 1:04 am 
Offline
Power Poster
Power Poster
User avatar

Joined: Tue Dec 23, 2008 8:39 pm
Posts: 1321
The usage is documented under Extensions -> Tags -> Content

In your template:
Code:
{content block="background" label="Background Image" oneline="true" assign="background_image"}


When you edit your page, you will have an entry called "Background Image".. The value will be in a Smarty variable called $background_image

I would put this content block before the <head>. This section gets processed first, then the <body>, then the <head>. Then put:

Code:
<body style="background-image:url(uploads/images/{$background_image});">

(adjust the path above to fit the location of your images)


Top
 Profile  
 
 Post subject: Re: How to add a class to body tag
PostPosted: Fri Apr 08, 2011 1:17 am 
Offline
Forum Members
Forum Members

Joined: Thu Sep 16, 2010 11:56 pm
Posts: 44
This is great help. I will do that tonight and see how it works out.


Top
 Profile  
 
 Post subject: Re: How to add a class to body tag
PostPosted: Fri Apr 08, 2011 4:33 pm 
Offline
Forum Members
Forum Members

Joined: Thu Sep 16, 2010 11:56 pm
Posts: 44
Hi, this is an easy solution, and works well.

I still need to be able to add a css class to the body tag though. The background images that are being used have css position properties. Is that possible to do?

Thanks!
Camille


Top
 Profile  
 
 Post subject: Re: How to add a class to body tag
PostPosted: Fri Apr 08, 2011 5:41 pm 
Offline
Dev Team Member
Dev Team Member
User avatar

Joined: Tue Aug 12, 2008 9:30 pm
Posts: 1984
Location: Feldkirchen in Kärnten, Austria
Code:
<body class="{$page_alias}">

In stylesheet
Code:
body.my-page-alias {
  my: style;
}

_________________
CMSMS Blog - I do this!
Forge profile
Github profile
Twitter
=============================================
Support CMSMS


Top
 Profile  
 
 Post subject: Re: How to add a class to body tag
PostPosted: Fri Apr 08, 2011 6:37 pm 
Offline
Forum Members
Forum Members

Joined: Thu Sep 16, 2010 11:56 pm
Posts: 44
I wish it could be that simple. The site has at least 100 pages, each with different page aliases.


Top
 Profile  
 
 Post subject: Re: How to add a class to body tag
PostPosted: Wed May 02, 2012 8:24 pm 
Offline
Dev Team Member
Dev Team Member
User avatar

Joined: Fri Nov 30, 2007 9:15 am
Posts: 332
Hi Camilep,

This is the UDT i sometimes use if i want to have specific css rules for groups of pages or individual pages:
http://wiki.cmsmadesimple.org/index.php ... page_class

Just try it and you'll be pleasantly surprised!!

Greetings,
Manuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
A2 Hosting