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?
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
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
Tagged:
4
Comments
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?
Vanilla Forums COO [GitHub, Twitter, About.me]
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
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".
There was an error rendering this rich post.
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".Now go to "Forum / Categories". Look for the section "Page Layout" 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.
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..
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 :-)
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 :-)