XF 2.1 How do we create an add-on that contains only template modifications?

Wildcat Media

Well-known member
I have some template modifications to make, and am using our private testing forum as the development platform. This add-on will have no settings, no database usage, or anything else. It will simply be a set of nine template modifications. (I could create an option to turn it on/off but I can always add that later on, even though I don't forsee using it, as I could disable the add-on just as easily. It will not be distributed beyond our own usage.)

Just going through a couple of tutorials (like "Let's build an add-on" provided by XF), I am guessing that I roughly have to do things in the following order:
  • Put forum into development mode.
  • CLI: Create the add-on at the command line.
  • Edit the JSON file with added information (optional).
  • Create the template modifications beneath the add-on I've just created.
  • ? (What do I need to do to create an install/upgrade/uninstall? Or do I need it?)
  • CLI: Build the add-on into a ZIP file.

I feel like I'm missing something...?

Where do the template modifications get written to an addon? Is this done in the Build process?
 
They are written to the add-on when they are created. They will be included during the build process.
Good news--it worked as expected. 👍👍 I uninstalled the add-on and reinstalled it--everything's working perfectly.

This is a very nice system XF has built for developing add-ons. My days of coding have long passed, but this was relatively easy.

Now that I know how it's done, I can undo all of my template edits, revert the affected templates, and install the modifications as add-ons instead.
 
Can phrases be exported as well? I can edit phrases.xml manually to make it do what I want, but there has to be an easier way. I've tried adding my phrase but it is not being tied to the add-on. From Let's Build an Add-on:

Under "Appearance" go to "Phrases" and click "Add phrase". Make sure your add-on is selected. The "Title" of the first phrase will be "demo_portal_featured" and the text will be simply "Featured". Click "Save and Exit". Click "Add phrase" again. The "Title" for the second phrase will be "demo_portal_featured_hint" and the text will be "Featured threads will appear on the Portal page."

So I go here, choose my add-on from the list (covered in yellow) where I find nothing, as expected:

1585671679755.png

Click the Add Phrase button:

1585671699131.png

Nowhere to choose which add-on the phrase is used for. Indeed, if I save my phrase here, I return to the phrase viewer above. The phrase is there under "Any" (and works fine in the template) but not specifically tied to my add-on. What am I missing?
 
You want to add your phrases to the master language. If you're adding a phrase to the master language, you're getting an additional field on the phrase add/edit screen that lets you select an add-on that the phrase is associated with, and will be exported with.
 
You want to add your phrases to the master language.
💡 OK, that makes sense! I wasn't sure if we were supposed to touch the master language or not. (Like we don't touch the master style.) Thanks!
Be aware that you have to be in debug/development mode to be able to access the master language and master style.
Already there--that's where I'm adding the template modifications. 😉
 
💡 OK, that makes sense! I wasn't sure if we were supposed to touch the master language or not. (Like we don't touch the master style.) Thanks!

Already there--that's where I'm adding the template modifications. 😉

It's pretty much the same concept for master language and master style. If you add new stuff (templates, phrases) for your add-ons, you add them to master style, and if you're modifying templates (your realistically don't want to modify phrases), you'll use template modifications.
 
It's pretty much the same concept for master language and master style. If you add new stuff (templates, phrases) for your add-ons, you add them to master style, and if you're modifying templates (your realistically don't want to modify phrases), you'll use template modifications.
Excellent, that clears things up. Fortunately I'm not at the level where I'm adding templates, just modifying existing templates for two different styles (where I sometimes have to make a separate modification for each style).

Thanks much!
 
I have some template modifications to make, and am using our private testing forum as the development platform. This add-on will have no settings, no database usage, or anything else. It will simply be a set of nine template modifications. (I could create an option to turn it on/off but I can always add that later on, even though I don't forsee using it, as I could disable the add-on just as easily. It will not be distributed beyond our own usage.)

Just going through a couple of tutorials (like "Let's build an add-on" provided by XF), I am guessing that I roughly have to do things in the following order:
  • Put forum into development mode.
  • CLI: Create the add-on at the command line.
  • Edit the JSON file with added information (optional).
  • Create the template modifications beneath the add-on I've just created.
  • ? (What do I need to do to create an install/upgrade/uninstall? Or do I need it?)
  • CLI: Build the add-on into a ZIP file.

I feel like I'm missing something...?

Where do the template modifications get written to an addon? Is this done in the Build process?
I was just searching around and you had almost all of the same questions I have about doing this, but I have one more....

I understand how to make a template modification to a default template and then build the add-on for it. But how do you include a new, custom template in the add-on also? Do you have to create the custom template, then use template modifications to include the custom template somewhere else? Like include mycustomcss.less in PAGE_CONTAINER or even extra.less? Or would that be redundant as mycustomcss.less is already going to end up in the add-on file?

Edit: And including custom style properties in the built add-on would also be part of my question.

Edit again: I see it now - I have to be using the master style.
 
Last edited:
But how do you include a new, custom template in the add-on also?

Yep, it was covered here:

It's pretty much the same concept for master language and master style. If you add new stuff (templates, phrases) for your add-ons, you add them to master style, and if you're modifying templates (your realistically don't want to modify phrases), you'll use template modifications.

What I will add is that when you are adding a template, you scroll down to the bottom of the template editor window and choose the add-on which you want to associate your template with:

1684881592703.webp

What you do here is choose your own addon which you are working on, and that is what will tie the template to the add-on. This works for other things in the XF system, like template modifications, and adding phrases or anything else. Then when you build your addon, these are all bundled into the ZIP file which will contain everything needed to install it.

And as Lukas says, always add new templates, phrases, etc., to the master style. The only time that differs is if you are making template modifications for individual styles you have installed (which I do often).

It took me a bit to figure this all out but once you get a feel for how XF works, it's intuitive.
 
Yep, it was covered here:



What I will add is that when you are adding a template, you scroll down to the bottom of the template editor window and choose the add-on which you want to associate your template with:

View attachment 286376

What you do here is choose your own addon which you are working on, and that is what will tie the template to the add-on. This works for other things in the XF system, like template modifications, and adding phrases or anything else. Then when you build your addon, these are all bundled into the ZIP file which will contain everything needed to install it.

And as Lukas says, always add new templates, phrases, etc., to the master style. The only time that differs is if you are making template modifications for individual styles you have installed (which I do often).

It took me a bit to figure this all out but once you get a feel for how XF works, it's intuitive.
This is kind of off-topic now, but I gotta tell someone because I'm excited....

I completed my first add-on yesterday after following the macOS dev environment and let's build and add-on tutorials. I feel like I unlocked a whole new side of XenForo. I have so many ideas for small tweak type add-ons that I know people want (including me).

I guess I can attach what I made if anyone is interested in evaluating it. What it does (for now), is add two new style properties: 1) limit the width of the header and footer so they don't stretch at all, and 2) move the sidebar to the left (sidenav position) on the forum list page. These are just two new style properties from my list of many that I plan to add.
 

Attachments

Most of my visual modifications are done through addons. Even if their only purpose is to add to the extra.less template, I find it easier to manage my modifications if they are created as template modifications. If there is an issue, I can turn it off with a switch in the admin panel. I can also use it on more than one forum if I need it elsewhere.

One template mod I made for myself recently was to change the behavior of font weight settings. As I use variable fonts for one of my projects, having them limited to increments of 100 wasn't going to work. I also added more font weights to adjust. I could have done all this through extra.less but wanted it in a more clearly modifiable form I could tweak on the fly.

I hate to say that it's "fun" to figure out the addon system, but it is easy enough for me to work with and mostly understand how it works. If I don't understand something, I look at other addons I've downloaded and dissect them a little to see how they made something work. My mind is too far gone to do serious coding so anything requiring PHP coding is nearly impossible for me to do now. But that doesn't mean I can't take on addons I need for small tasks.
 
I can also use it on more than one forum if I need it elsewhere
That, and it will also apply to all styles (if you use multiple) without having to mess with their templates, or the need to keep track of outdated templates that you caused, etc.

If I don't understand something, I look at other addons I've downloaded and dissect them a little to see how they made something work.
Same. I wondered if I was the only one, lol.

My mind is too far gone to do serious coding so anything requiring PHP coding is nearly impossible for me to do now.
Also same. This is just a slow/casual hobby of mine. I do want to release my add-on idea (and I will) but it will never be anything more than a bunch of style properties based on small CSS and HTML tweaks that most of us often want to change on a fresh XF install. I enjoy the CSS and HTML stuff but going deeper than that in development is probably not for me.
 
I had written two complete, custom catalog/shopping cart systems for clients, made dozens of sites from the ground up, etc., but eventually got so burned out on it all that I had to quit. And since that was nearly a decade ago, I can't wrap my head around coding much anymore. I'm happier these days to use existing systems (XenForo, reluctantly WordPress, etc.) and fit them to my needs.
 
Top Bottom