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.

Can I have different themes per category?

edited January 2011 in Vanilla 2.0 - 2.8
Hi,

right now I have a forum where every subforum has its own theme. Just as if they were their own forums.

Is this possible with Vanilla?

I can also imagine setting up multiple forums having the same userbase. Would that be a problem?

Cheers
dakira

Comments

  • oliverraduneroliverraduner ✭✭
    edited January 2011
    The Theme seems to be set at the very beginning when browsing any page of the forum. So I tried modifying the "bootstrap.php" to load a different theme, depending on the current Category.

    if (IsMobile()) { $ThemeName = C('Garden.MobileTheme', 'default'); } else { $CategoryModel = new CategoryModel(); $_CategoryData = $CategoryModel->GetFull(); foreach ($_CategoryData->Result() as $Category) { switch ($Category->Name) { default: $ThemeName = C('Garden.Theme', 'default'); case 'category1': $ThemeName = 'default'; break; case 'category2': $ThemeName = 'EmbedFriendly'; break; case 'category3': $ThemeName = 'mobile'; break; } } }

    But this did not work. (Neither did it break anything, though)

    Maybe @Tim has a tip, how to achieve a change of Theme per Category?
  • Thx for looking into this Oliver! I'd be great if any of the devs had more information on this. I'm still familiarizing myself with the source, so any pointer in the right direction would be very welcome. As far as I can see it won't be possible right now to add this functionality as a plugin which is too bad.
  • Hm, I'd really like to know if @Mark, @Tim or @Todd have any pointers how to achieve different themes per category. Any hints would be greatly appreciated. When I implement this, I could supply you with a patch against the current git, so that you could put it into the regular releases. Unfortuantely I have limited time to put into this, so just a little pointer in the right direction would be nice.
  • TimTim Vanilla Staff
    I've never thought about it. I don't know how you'd do it, but I imagine you could hook an event somewhere. You're on your own though.

    Vanilla Forums COO [GitHub, Twitter, About.me]

  • @oliverraduner @dakira

    The code you have there just iterates through all possible categories, it has no way of knowing which (if any) category has been selected. Further to that, that section only affects the bootstrap.php file itself as everywhere else (as far as I can tell) is based around what happens in the constructor of "library/core/class.controller.php". Basically it calls the function "Theme()" which just looks up the theme from the main configuration in the same way as in the bootstrap file:

    if (!function_exists('Theme')) { function Theme() { return C(!IsMobile() ? 'Garden.Theme' : 'Garden.MobileTheme', 'default'); } }

    So you cannot affect this via bootstrap.php.

    One ugly option is to change the $this->Theme attribute within the various classes' methods when the category is known (class.discussioncontroller.php, class.categoriescontroller.php, etc.). You might be able to do this more efficiently by adding a custom constructor method but I am not yet clear where in the code category name gets set up. Adding logic to look for it in DiscussionController::Index() does work however but that means you would have to modify every single method of every single class to make the check.

    Possibly a cleaner choice would be to use the "BeforeAddCss" event called by Gdn_Controller::RenderMaster. I am not well versed enough yet in using events to know how to call that from a plugin but embedding this test code in RenderMaster() changes the theme only for a specific category:
    if(isset($this->CategoryID)) { if($this->CategoryID==4) $this->Theme='EmbedFriendly'; }

    Since the BeforeAddCss event happens early in the render process, it should be safe to change the theme at that point I think.

    Cheers
  • @Tim and @codegrunt. Thx for your input. I'll have some free time this week to further look into this. Doesn't look too bad.

    This leaves me with one problem that should be easy to solve: When I go to "/categories/all" I get a list of all categories. Is it somehow possible to get a list of all subcategories of a given root-category in the same style? Something in the lines of "/category/general/all".
  • @dakira, can you explain in a more concrete way, maybe with an example?

    There was an error rendering this rich post.

  • @UnderDog: Basically I want the same thing that regular (web 1.0) forums do these days. Here's an example:

    I have a record label with 5 bands. Every band should have its own subforum. Imagine a structure like this:
    • The Rockband
      • Releases
      • Concerts
    • The Ska Doodlers
      • Releases
      • Concerts
    Now when someone selects the category "The Rockband" they should have some visual cue that there are subforums here. The best would be if they were just listed at the top or in the way all categories are listed when you open "/categories/all".
  • Yes if you click on a forum with subforums, it does not show those subforums.
  • UnderDogUnderDog MVP
    edited February 2011
    Now when someone selects the category "The Rockband" they should have some visual cue that there are subforums here.
    In your dashboard go to "Appearance" / HomePage. You can choose between "All Categories" and "Categories / Discussions", but you probably already have done that.

    Now go to "Forum / Categories". Look for the section "Page Layout"
    Configure how nested categories are displayed to users.

      Place nested categories in a comma-delimited list when they are ...
    • Display root categories as headings.
    • Do not display the categories in the side panel.
    In my site I've displayed the root categories as headings and I showed my nested categories as a comma delimited list when they were more than 2 levels deep.

    You might want another setting, but try some of these settings...

    Also check out this blog post (with video tutorials):
    http://vanillaforums.com/blog/video/new-video-tutorials-on-screenr/
    It's exactly a good example of handling categories.

    There was an error rendering this rich post.

  • @Underdog: I already tried everything you say.. The problem is still the same: When I select a root-category the user has no visual cue of the available sub-categories unless I show ALL categories in the sidepanel (which I don't want).

    Anyway.. this at least should be easy enough to implement through a plugin. Another thing I'll have to look into.

    Another nice feature would be, if you could only display the available nested categories in the side-panel. Like when you are on the all discussions page, you see all available categories. But when you select a root category, you only see a list of the categories nested in this root-category..
  • @dakira did you find a solution to either of your questions? (Custom theme per category and a way of listing sub-categories or the posts in those sub-categories?)
  • I highly suggest using a single theme that has checks for category in it and outputs different styles accordingly. Theme-switching would be pretty intense and unnecessary.
  • @Lincoln

    Any example?

    As I understand we must do something similar to your Plugin based JS CDN approach.
    Looking at header items and replacing them before rendering view.

    May be we could have FireEvent's in AddJSFile and AddCCSFile with ability to change original even argument (file name or URL) and it'll be used by this core functions?
    Especially if we'll have application, exact view and agruments as other event arguments :-)
  • @tester13 No example, just a suggestion based on my experience. I have no idea what the rest of your post is going on about or why you'd want to do that.
  • I think you know that rest of my message is about.

    It is about making Events for handling JS and CSS files.
    So, people could use them in plugins or themes.
    Changing style according to category, user, etc, for example.

    It is not bad idea :-)
  • Hey. Just wanted to let you know I'm still alive. I've got some spare (paid) time in the the next couple of weeks and my employer needs this done, so I'll probably make some progress on this.
Sign In or Register to comment.