Fork me on GitHub
Current release is 2.1.6 (21 Nov 2014).

Users who have not yet upgraded to 2.1 should get security release 2.0.18.14 (1 Nov 2014). We will stop providing these security releases to 2.0 at the end of this year.

[Solved] How do I create a unique header for each category in Vanilla?

ericcarlericcarl New
edited October 2011 in Vanilla 2.0 Help
I'm working on a theme and I'm attempting to set it up so that each category has unique content at the top of the page. Specifically we're using Vanilla to host some online classes and we'll need to embed a different video at the top of each category. Is there a simple way to do this in Vanilla's theme development or will I have to take a different approach? I've got a quick visual example of what I'd like to do here:

http://gnomonschool.com/temp/category-player.jpg

Thanks for any help!

Best Answers

  • ToddTodd Chief Product Officer Vanilla Staff
    edited October 2011 Answer ✓
    In the vanillaforums.org theme we put the following in our theme hooks file:
    public function CategoriesController_AfterBreadcrumbs_Handler($Sender, $Args) {
    $Description = $Sender->Data('Category.Description');
    if ($Description) {
    echo ''.$Description.'';
    }
    }
    You could then put the html you want in your category's description.
    marthajane77
  • ToddTodd Chief Product Officer Vanilla Staff
    edited October 2011 Answer ✓
    You can add an extra column to the GDN_Category table. Then you can grab $Sender->Data('Category.YourField') instead of Description.

    To add the column in code you would do something like:
    Gdn::Structure()->Table('Category')->Column('YourField', 'text', FALSE)->Set();
    You can put that in your theme hook's setup method and it will be called when you enable the theme.

    You'd probably want to add that field to the add/edit category UI. That's different depending on your version of Vanilla you are running. I think 2.0.18 has some stuff to make this a one line type of thing.
    marthajane77

Answers

  • No ideas on this one? I was thinking I might be able to do something in PHP that displays specific HTML based on what's in the URL, but my PHP chops are pretty limited and there's probably a much more elegant way to do it.
  • ericcarlericcarl New
    edited October 2011
    Thanks so much Todd. Unfortunately I must be doing something wrong as it doesn't seem to be working. Here's what I've done:

    I've added a file called class.mc2011themehooks.php to my theme folder location here:
    vanilla-2/themes/MC2011/class.mc2011themehooks.php
    And this is all of the code inside that file (I'm not sure why the <br /> is displaying on line 1 here, it's not actually in my file that way):
    <?php if (!defined('APPLICATION')) exit();

    class mc2011ThemeHooks extends Gdn_Plugin {
    public function CategoriesController_AfterBreadcrumbs_Handler($Sender, $Args) {
    $Description = $Sender->Data('Category.Description');
    if ($Description) {
    echo ''.$Description.'';
    }
    }
    }
    And I have some plain text in my Category descriptions that I assume should now be visible on my Category pages, but they aren't displaying.

    I wasn't sure about the first line of PHP there. I included it because I also saw it in the theme hook files from other themes. If I leave it out all of the code in my theme hooks file appears at the top of my Dashboard, like this:

    http://gnomonschool.com/temp/vanilla-hook.jpg

    Any idea what I may be doing wrong? Thanks a bunch!
    marthajane77
  • ToddTodd Chief Product Officer Vanilla Staff
    It looks like your hooks are being included fine. Maybe the event isn't getting thrown. Try the Eventi plugin to see if there is an event you can subscribe to.
  • Thanks Todd, got it! I was able to use the CategoriesController_BeforeDiscussionTabs_Handler event and that is working. Hooray!

    If I decided I didn't want to use the category description what would my options be? Is there some way to create a custom element I could call in instead of the category description?
  • Thanks a bunch of Todd, you have been a great help! Really appreciate it.
Sign In or Register to comment.