Invision Community 4: SEO, prepare for v5 and dormant account notifications By Matt November 11, 2024
Michael Posted December 22, 2010 Posted December 22, 2010 When using template hooks, we have the cool replaceOutput function that lets us do some more direct manipulation of the actual output. I have found, though, that this function is really only useful if we want to add to the output at specific locations; it's not really all that useful to do any actual replacing. The reason for this is, while we get the $output and $key variables which tell us the HTML source and the HTML comment tag for the hook point starting location, we don't have anything that tells us where the hook point ends. In uses of this function for things like the 'promote to article' button in IP.Content, the function gets used so you can find a page location and add a button after that. If we wanted to, say, actually replace a page element with something else, we can't because we don't always know where the element ends. Say I wanted to replace the Report button in posts with something else. I could hook into the 'canReportPost' hook point, and using the replaceOutput function I'd be able to see where each of these report buttons showed up in the content because the hook key comment starts there. But I don't necessarily know where these elements end if I wanted to do something like a preg_replace or str_replace on them. Sure, on the IP.Board skin they are <li> elements, so I could look for a </li> tag after the hook key comment, but other skins may change that to be an image file or something. What I'd like to see is for the $output variable to not only have the comments indicating where a hook point starts, but also where it ends. That way, we could do an actual replacement of the content of that element.
roblgs Posted March 8, 2011 Posted March 8, 2011 Hi, Unless I'm missing something, and I'm a new IPB user, so may be barking up entirely the wrong tree, but what's to stop you manually setting up the start/stop hook points yourself... You could start with hook.start.$key and end with hook.end.$key and write the necessary code for handling that within your hook, and replacing whatever lies between. I think... Rob
Michael Posted March 8, 2011 Author Posted March 8, 2011 That defeats the purpose of the hooks system. What the hooks system is supposed to let us do is to add our stuff, or change things, without having to make any edits to the basic forum code. If the only solution is to edit the template to add those hook points myself, then I might as well forgo using a hook at all and just make my changes right in the template.
pt2ph8 Posted March 8, 2011 Posted March 8, 2011 That defeats the purpose of the hooks system. What the hooks system is supposed to let us do is to add our stuff, or change things, without having to make any edits to the basic forum code. If the only solution is to edit the template to add those hook points myself, then I might as well forgo using a hook at all and just make my changes right in the template. Couldn't have said it better.
roblgs Posted March 9, 2011 Posted March 9, 2011 OK, I see your point... Documentation on this is rather limited, which together with my unfamiliarity with the system, isn't helping any. I agree that for this to work properly as a 'replace' tool there really does need to be a corresponding end hook, that doesn't currently exist. Rob
Recommended Posts
Archived
This topic is now archived and is closed to further replies.