We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3955
    • 3 Posts
    Hi,

    I am a new Modx user and so far really like it. I’ve searched the forums for a solution to my question, but didn’t find what I was looking for, so please forgive me if it does exist in the forums already:)

    I would like to have a unique body ID <body id="whatever"> generated for each page in Modx. Then I can style the pages differently with CSS based on that ID. Is this something that is doable? If so, how?

    Thanks in advance for any and all feedback!

    Thnx!
    Brian
      • 25663 MODX Staff
      • 12,272 Posts
      1) Create a TV called "bodyID" (or whatever) that’s assigned to all templates.

      2) At Input Type: DropDown List Menu

      3) Under Input Options:
      inheritted==||Option 1 Text==opt1val||Opt 2 Text==opt2val||Opt 3==opt3val (and so on ...)

      4) Under Default Value: @INHERIT

      5) In your template:
      <body id="[*bodyID*]">

      Now you’ve got a handy set of default body ids to keep things consistent, and you only have to set the value at the top-most container document (it automatically will flow down to all it’s children).
        Ryan Thrash, MODX Co-Founder
        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
        • 3955
        • 3 Posts
        Thanks, Rthrash! That’s exactly what I was looking for! However, being extremely new to this, I was hoping you could help just a bit more:) I created my template variable, but am unsure how to implement the input option values. I want the unique body id to be on every page created in my document tree. I can’t figure out how to take your example text below and use that syntax for my docs. Thanks again for your quick reply!

        inheritted==||Option 1 Text==opt1val||Opt 2 Text==opt2val||Opt 3==opt3val (and so on ...)
          • 22303 MODX Staff
          • 10,725 Posts
          Well, you could do something like this:
          <body id="body[*id*]">...
          or this:
          <body id="[*alias*]">...

            • 3955
            • 3 Posts
            Thanks, Opengeek! That’s exactly it. No TV required. I appreciate it. Thanks also to Rthrash for his solution!