ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Global template group variable

August 29, 2011 11:42pm

Subscribe [3]
  • #1 / Aug 29, 2011 11:42pm

    Ryan

    31 posts

    Is it possible to return the name value of the template group? I want to use this value as a class for the body.

    I’m needing something similar to the URL Segment Variables, though I don’t think this works on the site index.

    For now I’m using embed variables in my templates, and returning the value {class} in the include;

    <body class="{embed:class}">
    {embed="{include_header}" class="index"}

    Though, I don’t see why there wouldn’t be something global for the template group name (eg: {template_group}).

    <body class="{template_group}">

    I could use this variable directly in my include, without having to specify embed variables on every template that includes this.

    Does a variable for this exist? Or I could write a conditional for {if !segment_1} ..

  • #2 / Aug 29, 2011 11:55pm

    Ryan

    31 posts

    I’ve decided to use {segment} variables for the time being.

    <body class="{if segment_1}{segment_1}{if:else}index{/if}">
    ...
    <body class="{embed:class}">

    Though if anyone knows of a more legitimate solution please let me know.

  • #3 / Aug 30, 2011 8:57am

    Sue Crocker

    26054 posts

    Hi, Josephs. I don’t see any reason why your code wouldn’t work. Just make sure to use only one body statement, of course.

  • #4 / Aug 30, 2011 9:43am

    Ryan

    31 posts

    I don’t see any reason why your code wouldn’t work.

    No problems with getting it working, I was just curious whether there was a simpler solution instead of running a conditional.

    Perhaps create another feature suggestion?

  • #5 / Aug 31, 2011 4:11am

    John Henry Donovan

    12339 posts

    Josephs,

    Have you seen NSM Body Class for EE?
    It may do what you wish

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases