Plugins for custom themes [RESOLVED]
I need to put out the usual disclaimer, I am a total newbie. That being said, here is my question...
I've created a custom theme under the "themes/foobar" folder. In that folder, I have created another folder views which contains my default.master.tpl. Everything works as expected up to this point. I've been trying to figure out more of how everything works and I was looking at the "Theme Hooks" section (https://docs.vanillaforums.com/developer/addons/theme-hooks/). I was following their example for how to create the plugin in the theme outlined in that link that I just posted., however I am having no luck. The example theme hooks file should apparently override the filter count string class in the panel, but the class shows up nowhere in the page.
I saw this post (https://open.vanillaforums.com/discussion/35717/use-the-plugin-on-a-custom-theme), but I have all of the assets on the page, so I'm not sure what to do. What am I doing wrong? Thanks for the help!
Comments
If you have created the theme hooks file after you have created the theme, it might be acache issue. Try if deleting the theme related files in /cache already helps
Just to be sure, could you add an addon.json file to your theme?
https://docs.vanillaforums.com/developer/addons/addon-quickstart/
{
"type": "addon",
"key": "foobar",
"name": "foobar",
"description": "This is a theme!",
}
And stupid question but you have your theme enabled, and when you change the template changes are visible? It's just the themehooks file that isn't working?
@Caylus: shouldn't it be
"type": "theme",
?@jsaavn: If you use the example, be sure to make it fit your theme.
class MyThemeNameThemeHooks extends Gdn_Plugin {
must beclass FoobarThemeHooks extends Gdn_Plugin {
.I'm not sure if it is important if the file is named
/themes/foobar/class.themehooks.php
or/themes/foobar/class.foobar.themehooks.php
. I would recommend the second name, though.But as I've said before: maybe everything is alright but only the cache is outdated. Try deleting
/cache/theme/foobar.php
Starting in Vanilla 2.5 themes plugins and applications have been combined into 1 format - Addons!
https://docs.vanillaforums.com/developer/addons/#addons-and-plugins-and-themes-oh-my
So I think it's best to stick to "type":"addon" for now, to make it (hopefully) more future version proof.
@Caylus @R_J thanks for all the responses!
Ok, so my addon.json file has the type set to addon and the plugin class name is set to FoobarThemeHooks. The plugin file name is class.foobar.themehooks.php.
It seems that clearing my theme cache has now allowed the respond button to show up underneath an individual discussion title. So, sorry, such an easy fix!
However, what I was really hoping to get to work was the function override in the bottom of this example (https://docs.vanillaforums.com/developer/addons/theme-hooks/). From my understanding, that function override for the "filterCountString" should be right around here, correct?
When I inspect the HTML, I don't see the new class on the and I've gone so far as to just search "a-new-css-class" in the page source just to make sure I wasn't missing anything. Is this the best place to do those function overrides for changing classes or overriding functionality, etc.? Thanks again for answering this and let me know if you need more details.
Disregard the previous post I was looking at it wrong and I can now see the class addition and function override! It wasn't for the categories list, but for the "My Discussions" count in the panel. Everything is working and thanks again for the help!