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.
Additional Categories Layout Tutorial
Cansili
New
Is there some sort of a guide on how to add more categories layout?
I was able to alter the Homepage settings to add options for another layout (https://vanillaforums.org/discussion/31746/override-homepage-settings-views) but I'm stuck now on where to proceed to create the views for that option.
0
Comments
The two existing options are "modern" and "table" and this setting is stored in the config setting
Vanilla.Categories.Layout
. Your custom setting should use that config setting for a custom value e.g. "groovy"While there is no option at the beginning of the index method of the categories controller, there is an event "BeforeCategoriesRender" fired before the view is rendered. So basically it should be possible with a piece of code like that:
I'm sorry but I don't know much about PHP ( should have said this earlier ).
I change the layout in config.php to "groovy", put the code above in class.themehooks.php and created a file groovy.php with simple "echo" codes.
The result is that it reverted to the modern layout and got this error:
Well it could have worked that way... I had not taken a closer look at the source, so I have not seen that the categoriesController index method isn't used for displaying the different layouts. Here is the code that is responsible for the "routing":
=> If the layout is neither "mixed" nor "table" a method called "all" will be called. At the end of this method you'll find
$this->render();
which normally calls a view with the same name as the method itself. So the methods name is "all" and that's why we have to override the "all.php" view.Create a testfile. While
/themes/yourtheme/views/all.php
is possible, I'd suggest/themes/yourtheme/views/categories/all.php
. Just to be precise.If you've created that testfile and go to your forum, you should see the output of your testfile.
Now change the content of your all.php to this:
That is somewhat ugly, but it will work. You need to create a groovy.php and that will be displayed when you open the categories page and the layout is set to "groovy".
It is ugly because we put controller logic in the view, but I think it is okay in that case.