-
- 24,544 Posts
I think the closest thing to that would be to create a Template Variable (TV) and put the "class" name (or whatever you want) in the TV value for each page. If you name the TV 'Class', you could put this tag in the template or text where you want the class name name to appear:
You can also do this to control the style of the page:
<div id="[[*Class]]">
</div>
-
- 19 Posts
Hi BobRay
I want to do something like that but my header is separate. So I can't just put different class names on header (if that's what you mean).
What I can do though is when I call the header, for example in my single news page, I'd do something like this:
[[$header var=class="single-news"]]
In the header chunk I'd say:
<body class="[[$var]]">
But I'm sure this is not the correct syntax. Would you know? I'm sorry, I'm really just starting with Modx.
-
- 24,544 Posts
Unfortunately, the template used is only available as a number if you use a tag. You can cheat, though and name chunks with the template ID in the name (in parentheses next to the template in the tree) and put what you want to display inside the chunk. IOW, the chunks would be named template-1, template-3, template-5, etc. and you'd use this tag to set the class:
<body class="[[$template-[[*template]]]]">
The inner tag will resolve to the Template's ID, then the outer tag will be replaced with the contents of the specified chunk.
-
- 1,613 Posts
I sometimes do it by using;
<body class="page-[*id*] [*parent:is=`4`:then=`news`:else=``*] [*id:is=`4`:then=`newsoverview`:else=``*]">
(This is for evolution but can be done by revolution aswell with different calls)
If template can be used that would be better if you use different templates.
(I always try to reduce the ammount of templates.)
Evolution user, I like the back-end speed and simplicity
discuss.answer
-
- 24,544 Posts
Thanks for the kind words. I actually have an even better answer now:
<body class="[[TemplateName]]" >
/* TemplateName snippet */
$query = $modx->newQuery('modTemplate', array(
'id' => $modx->resource->get('template'),
));
$query->select('templatename');
return $modx->getValue($query->prepare());
It's faster and uses less memory.
-
- 19 Posts
That one works like a charm Thanks BobRay!