XF 2.1 Add-on development first time coming from WordPress, Drupal dev. I'd like to use more PHP.. Possible?


New member
Hi All,

I'm new to Xenforo, just spent a few hours reading the docs, tutorials and the forums. I bought a license and have it up and running on my local development machine now.
I'm a Software Engineer, very good with PHP, HTML, CSS

I've written a plugin for Wordpress that displays advertising links, images and text, and it does that after consulting external API's. Somtimes it reads from the local database (I see how to do that in Xenforo, no problem) or it caches results into the local database, etc. In short it does a lot of stuff in PHP before it decides what it's actually going to put on the screen.
I've ported that plugin to MediaWiki and Drupal without any problems. All those platforms all quiet similar actually.

Now that I'm diving into Xenforo, I see it's quite a bit different in how it handles add-ons.

All of those platforms use PHP and just let me register a call-back at a very specific render time (like before a post during the "page render" process) then I'm just in PHP where I can make all my decisions about what and how I want to display it.
I can access global variables or call functions that are part of the platform to check if a user is logged in or what kind of world I'm rendering into, I can call external APIs, etc. etc. I have access to all things PHP.
When I'm ready I just return all the HTML I want to be inserted into that exact spot in the process and we're done.

There are no "templates" like in Xenforo, and this templating langage doesn't seem as powerful as what I need.
I understand I can do little tid-bits like <xen:if is="{$post.position} == 0 AND !{$visitor.user_id}">
but that doesn't help me return a large chunck of HTML that was generated from calling external APIs and getting things from the database, etc.

So I'm wondering if I can do that kind of thing as a Xenforo add-on? i.e. register a call back in PHP and then just use that code to make all my decisions?
I keep seeing forum threads here where it looks like people are just messing with templates to get their desired result, but I need more power than that.

I'm actually aiming to do a couple of major things.

1. insert html in between forum posts when they're all displayed on a page (with 10 or 20 or them or whatever)
I'd like to be able to use PHP to determine if the person viewing the page is logged in, exactly what post number I'm inserting this after, etc.
So I'm wondering if there is a function I can override or a class I can extend, so that my code will get called and be given a bunch of context about where in the render process we're up to (which post etc)

2. Modify the content of posts at render time. Let's say someone posted a link to "http://something.com" as part of their post, I'd like to use PHP to modify that to "http://somethingelse.com" - note, I only want to do this at render time and I don't want to permanently modify the stored post in the database.
Again, I'm wondering if there is a function I can override or a class I can extend where the contents of a post will be passed in so I can modify it and then return it.

Are there sample plugins or code that are along these lines I can look at?

Does anyone have any advice or a direction I should be looking?

Thanks in advance for any and all assistance,

Lukas W.

Well-known member
You should likely start with the basics if you're not aquainted with the MVC concept. Templates shouldn't contain any logic beyond simple checks, so the majority of your code will go into a controller extension and a repository, with some view checks going into templates via template modifications.


New member
Hi Lucas,

Thanks for the reply, I appreciate it.
I've had a good read through that demo add-on example, and I have used MVC, but admittedly not for a few years.

Are there diagrams or explanations that show which Controllers handle various parts of the UI, and which Views render those parts?
How do I know where to dig in?

Again, any help is greatly appreciated.


Lukas W.

Well-known member
If you enable debug and development mode you can see the controller action and template that rendered the page by hovering over the cog icon in the debug line in the footer.