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

Rudy

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?
 

Jeremy P

XenForo developer
Staff member
Sounds about right to me.

  • ? (What do I need to do to create an install/upgrade/uninstall? Or do I need it?)
You don't need a setup file.

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.
 

Rudy

Well-known member
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.
 

Rudy

Well-known member
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?
 

Lukas W.

Well-known member
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.
 

Rudy

Well-known member
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. 😉
 

Lukas W.

Well-known member
💡 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.
 

Rudy

Well-known member
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!
 
Top