default userpic

Body ID

Vote 0 Votes

Hi. I'm needing to set a dynamic body ID in my Page template based on the page loaded, so that different CSS layouts can be used.

Would anyone be able to give any advice on how to do this?

I had read that using "> would do the trick, but that seems to set replace the BlogTemplateSetID with mt-blog... could I use some form of tagging or categories?

Thanks,

Barella

Reported on Movable Type 4.2

5 Replies

| Add a Reply
  • Depends on the template set you are using really, you could easily add your own var to make life easy.

    just add:


    <$mt:Var name="body_id"$>

    to your header template in the id section of the body tag (if it includes the body tag)

    Then when you call that header template use this:


    <$mt:Include module="Header" body_id="my-body-id"$>

  • Thanks Richard for your help.

    It seems to be working, but I'm struggling to work out the final piece.

    I've added

    <body id="<$mt:Var name="body_id"$>">
    

    to the Header 'Template Module' I've created, and

    <$mt:Include module="Header" body_id="my-body-id"$>
    

    in the Page 'Archive Template' - is this correct? Or should I be creating new Index templates for each body ID I require?

    Thanks,

    Barella

  • replace "my-body-id" with whatever you want the ID to be! If it's going to be based on the MTPageID then you may have to chuck it into a var before you put it in the Include tag.

    Where are these custom IDs coming from? i.e. how do you decide which page has what id?

  • Again thanks,

    I have about six different ids I'm needing to use, which are based on the grouping of pages within my site. I;m still struggling to understand how this could be passed in as a variable... possibly through tagging the pages and passing the tag as the id? Is that feasible?

  • Yes, that's a good idea, would break if you added more than one tag to a page tho!

    You could organize into folders and use the folder basename to set the id of the body.

    If you're using Pro, you could add a custom field to select the id required, then load that back into the header var.

    Or this plugin may be of use:
    http://plugins.movabletype.org/page-layout/

    (not tired it, but seems to do similar to what you are after)

Add a Reply

If you need to share template code, replace all the "<" signs with "&lt;" or use this utility.

Forum Groups

1773 6162

Last Topic: Excluding categories from blog by kholechek on Feb 9, 2012

86 302

Last Topic: website entries by masoud on Oct 26, 2011

1429 5077

Last Topic: What apocalypse hit this community in the middle of 2011? by 75th on Feb 10, 2012

694 2908

Last Topic: Blogspot to Movable Type by sdude on Feb 8, 2012

84 291

Last Topic: How to have some other characters in entry basename automatically written by Afshin Haghighatnia on Dec 22, 2011

173 737

Last Topic: About the MT version stated in HTML source by Alex E. Schneider on Feb 7, 2012

190 565

Last Topic: Analytics Reporting by michael webster on Feb 5, 2012

48 210

Last Topic: An idea and also a request by Afshin Haghighatnia on Jun 29, 2011

64 246

Last Topic: jQuery in MT 5.1 still at 1.4 - why? by perlmonkey on May 25, 2011

code.sixapart.com

137 478

Last Topic: Getting a thumbnail with xpath by Peter on Mar 13, 2011

222 720

Last Topic: Custom Field for Asset Not Appearing by android on Feb 9, 2012