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.
[Documentation] Can I override a plugin's view in a custom theme?
I'm working on a theme, and I'd like to change the functionality of the Tagging plugin. Namely, I'd like to override class.tagmodule.php
in my theme.
I know I can override the views in my theme, but what is the practice for overriding plugin modules like this?
Tagged:
0
Best Answers
-
x00 MVP
I provide this functionality on some of my plugins, especial where I am already overriding core views.
It is not a standard thing though, But I support it in principle, as it is consistent with application views
The principle of it is like so
$PluginFolder = basename(dirname(__FILE__)); $ThemeFolder = strtolower($PluginFolder); $Sender->ControllerName=''; $Sender->ControllerFolder=''; $ThemeViewLoc = CombinePaths(array( PATH_THEMES, $Sender->Theme,'views', $ThemeFolder )); if(file_exists($ThemeViewLoc.DS.strtolower($Sender->RequestMethod).'.php')){ $Sender->ApplicationFolder= ''; $Sender->ControllerName=$ThemeFolder; }else{ $Sender->ApplicationFolder='plugins/'.$PluginFolder; }
I use lower case folders within themes views folder as this is consistent with the current style
grep is your friend.
1
Answers
You can try extending the specific class and then rewriting whatever function you want to override in the parent class. This is one of the reasons why my theme comes with a plugin.
How do I structure my folders to extend a plugin? Do I need a
modules
folder, or should I be putting this somewhere else?You nees to replicate the original structure.. copy the original file and folders you want to override into the theme.
Vanilla Wiki, Tastes Great! 31,000 viewers can't be wrong. || Plugin Development Explained
I'm just not getting it.
In my custom theme, I want to override
TagModule::ToString()
. It exists invanilla-root/plugins/Tagging/class.tagmodule.php
. Can I override this in my theme's folder, allowing me to distribute a theme with custom functionality? If so, how should my folder structure be set up?I've tried putting this file in the following locations, to no avail:
vanilla-root/themes/my-theme/class.tagmodule.php
vanilla-root/themes/my-theme/modules/class.tagmodule.php
vanilla-root/themes/my-theme/plugins/Tagging/class.tagmodule.php
There may be better methods, but this is what I do:
If you know where this function is called from (probably from a Fired Event), you can temporary buffer the output and the grab the results and filter them to your liking. In your case, I would look for the contents of
TagModule::Tostring()
such as a div with a specific class/ID and then replace it with whatever you want. The DOM document is perfect for this.Here is an example of what I do to make all of the meta elements fit into an unordered list. I pulled this code snippet of the traditional plugin views/discussion/helper_functions/ line 76:
@mcu_hq Hmm... this seems a bit dirty. I was hoping to just be able to have my theme dictate the module to load, like it does with views.
Do themes not allow that functionality?
I don't think they do.
Unfortunate.
I provide this functionality on some of my plugins, especial where I am already overriding core views.
It is not a standard thing though, But I support it in principle, as it is consistent with application views
The principle of it is like so
I use lower case folders within themes views folder as this is consistent with the current style
grep is your friend.
I missed a piece... x00 do you put your code in helper_functions.php in your theme?
There was an error rendering this rich post.
no it goes the
Base_Render_Before
hook or a Create hook. basically any controller hook just before render.So the view is goign to be name of the request method lowercase.
grep is your friend.