• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
Creating a Template Based Add-On

Creating a Template Based Add-On 1.0.0

No permission to download
Compatible XF 1.x versions
1.2, 1.3, 1.4, 1.5
If you need to edit a XenForo template, you can either edit the template directly or use the built-in template modification system. With the template modification system, you can package template modification(s) as an add-on, export it from the source forum and import it into different forums or share the template modifications with others.

This tutorial will go over how to package a template modification as an add-on and will use the template modification suggested by Syndol in this thread as an example.

The first thing that needs to be done is to set the forum in debug mode.

Open up “library\config.php” and add the following line of code and save the file.

Code:
$config['debug'] = true;
1.png


Now that the forum is in debug mode, you can create an add-on. Go to Home -> Add-ons and click on “Create Add-on”.
2.png


Fill in the following fields and click on Save Add-on.
3.png

Next, go to Appearance -> Template Modifications and click on “Create Template Modification”
4.png


Fill in all the required fields.

In the Find box enter
Code:
#{xen:calc '{$post.position} + 1'}
In the Replace box enter

Code:
#{xen:calc '{$post.position} + 1'}/{xen:calc '{$thread.reply_count} + 1'}
5.png


Click on “Test Modification” to validate that it works. You should see the following:
6.png


Click on “Save Template Modification”.

Next, got to Home -> Add-ons and export the add-on.
7.png


You can now import this add-on into another forum just like you import any other add-on.

The end result, which you can download here.
8.png


Additional Modifications

The following are examples of additional modifications that can be packaged into an add-on

Template Conditionals

In this example, a template conditional will be added around a block of code.

In the Find box, add the entire block of code that you want to surround with the template conditional.

In the Replace box, the content of the Find box can be referenced by the $0 variable. This makes it very convenient to add the conditional statement around the block of code.
11.png

This block of code will not be shown in forums with IDs of 3, 40 and 111.

EXTRA.CSS

You can add entries to EXTRA.CSS and package them as an add-on.

Set the Search Type to "Regular Expression"

In the Find box enter
Code:
/^.*$/s
In the Replace box enter
Code:
$0
/* Enter CSS entries */
10.png


Phrases


Custom phrases can packaged into an add-on and referenced in templates.

Create the new phrase.
upload_2014-6-22_10-29-33.png


Add it to a template.
upload_2014-6-22_10-30-46.png


End result
upload_2014-6-22_10-31-32.png
Author
0ptima
Downloads
44
First release
Last update
Rating
5.00 star(s) 2 ratings

More resources from 0ptima

Latest reviews

Awesome step by step tutorial, that helps even those who didn't code yet to be bale to create an add-on. Clear enough. Hope to see more advanced tutorials (like add-ons with style properties options and ...).
Fantastic, This is what i am looking for :) since a while.