Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Options

Php template using $this->CssClass for body class | sections not being outputted

Using a default.master.php file, running Vanilla 2.1.10, here is the body tag in the template file:
<body id="<?php echo $BodyIdentifier; ?>" class="<?php echo $this->CssClass; ?>">

For some reason, that does not output the sections in the body class, like:
Section-DiscussionList, Section-Discussion, etc.

The home for example has the class:
"Vanilla Discussions index" rather than "Vanilla Discussions index Section-DiscussionList"

Those sections are included in 2.1.10 aren't they? Is that no longer the right way to output the class in a php template?

Comments

  • Options

    Ok, it works properly with the Baseline theme, so it's something wrong with my theme. Is that body tag setup properly for using a default.master.php file? Anything else I should look for?

  • Options
    hgtonighthgtonight ∞ · New Moderator

    @vrijvlinder uses PHP template files. Hopefully she can provide some insight :)

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • Options
    vrijvlindervrijvlinder Papillon-Sauvage MVP
    edited June 2015

    I would compare the two and make sure it contains all the necessary code in your theme. Almost all the themes I make are in php.

    For some reason, that does not output the sections in the body class, like:
    Section-DiscussionList, Section-Discussion, etc.

    Vanilla Discussions index is the correct class for the discussions list I have never seen Vanilla Discussions index Section-DiscussionList, that may be in your theme but it is not a default vanilla class that I know of. Who ever made your theme must have customized it.

  • Options

    They added the "Section-" type classes in version 2.1. They show up in the Baseline and Bittersweet default themes, and they show up on this site as well.

    But, they do not show up when I use my theme with a default.master.php file.

    I tried several other themes using a default.master.php file, and had the same result.

    I dug into the code, and in class.smarty.php, I found:
    $BodyClass = GetValue('CssClass', $Controller->Data, '', TRUE); $Sections = Gdn_Theme::Section(NULL, 'get'); if (is_array($Sections)) { foreach ($Sections as $Section) { $BodyClass .= ' Section-'.$Section; } }

    It looks like that section class is only getting added in the smarty class, so it's not going into themes with a php file.

    I modified my template right after the closing head tag to be:
    <?php $BodyClass = $this->CssClass; $Sections = Gdn_Theme::Section(NULL, 'get'); if (is_array($Sections)) { foreach ($Sections as $Section) { $BodyClass .= ' Section-'.$Section; }; } ?> <body id="<?php echo $BodyIdentifier; ?>" class="<?php echo $BodyClass; ?>">

    That seems to work perfectly, I get all of the different section classes all over the forum, which adds a ton of flexibility for design.

  • Options
    hgtonighthgtonight ∞ · New Moderator

    @almostbasic said:
    They added the "Section-" type classes in version 2.1. They show up in the Baseline and Bittersweet default themes, and they show up on this site as well.

    But, they do not show up when I use my theme with a default.master.php file.

    I tried several other themes using a default.master.php file, and had the same result.

    I dug into the code, and in class.smarty.php, I found:
    $BodyClass = GetValue('CssClass', $Controller->Data, '', TRUE); $Sections = Gdn_Theme::Section(NULL, 'get'); if (is_array($Sections)) { foreach ($Sections as $Section) { $BodyClass .= ' Section-'.$Section; } }

    It looks like that section class is only getting added in the smarty class, so it's not going into themes with a php file.

    I modified my template right after the closing head tag to be:
    <?php $BodyClass = $this->CssClass; $Sections = Gdn_Theme::Section(NULL, 'get'); if (is_array($Sections)) { foreach ($Sections as $Section) { $BodyClass .= ' Section-'.$Section; }; } ?> <body id="<?php echo $BodyIdentifier; ?>" class="<?php echo $BodyClass; ?>">

    That seems to work perfectly, I get all of the different section classes all over the forum, which adds a ton of flexibility for design.

    Rather than replicate the code, why not use the smarty template? Smarty templates help ensure that application logic is not in your template files.

    It doesn't really matter to me what you do, I am just curious :)

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

Sign In or Register to comment.