Creating a Template Based Add-On 1.0.0

PVS

Super Moderator
Thành viên BQT
Tham gia
28/02/2015
Bài viết
17,142
Được Like
12,745
Vnxf.vn - 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.

Mã:
$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
Mã:
#{xen:calc '{$post.position} + 1'}

In the Replace box enter
Mã:
#{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

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
Mã:
/^.*$/s

In the Replace box enter
Mã:
$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


Nguồn: xenforo.com​
 

Đính kèm

  • addon-postNumber.zip
    581 bytes · Lượt xem: 1

Top Bottom