1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to create simple add-on that just modify template

Discussion in 'XenForo Development Discussions' started by Dadparvar, Jan 8, 2016.

  1. Dadparvar

    Dadparvar Well-Known Member

    Hi,

    I have lots of modifications to my templates, that if one day I decide to change them to default (or for any other reason I decide to back to its default mode), I should start reverting them all.

    But if I do them by add-on, I can change it to default easily by disabling add-on.

    Is there any sample code or tutorial? If anyone knows how to make such simple add-on, appreciated if you share its tutorial with us.

    Thanks in advance
     
  2. wang

    wang Well-Known Member

    First you will have to place your developement forum in debug mode. Then you go to Template Modifications which can be found under the Appearances tab in your Admin Panel, click the Create New Template modification and fill in the fields there. But first you must also create an add on, so you can associate your template modifications with it.
     
    Dadparvar likes this.
  3. Dadparvar

    Dadparvar Well-Known Member

    Thanks

    I created an add-on. Then Clicked on "Create Template Modification".

    In "Template" filed I should write the name of the template that I want to find a code and modify it? Or I should write a new unique name?
    And how about "Modification Key"? And "Execution Order?

    Thanks
     
  4. wang

    wang Well-Known Member

    You are welcome :)

    Yes for the Template field. About the Modification Key, simply enter a name. That can be unique for each template though. You can leave Execution Order to the default 10. But I would recommend that you use a higher value and not the same number if you modify the same template twice. I have encountered a weird problem in the past when I was hooking into the same template twice and both Execution Orders were 10.
     
    Dadparvar likes this.
  5. Dadparvar

    Dadparvar Well-Known Member

    Thanks.
    Then How to associate it to add-on?

    Edit: Oops! found it.
     
    wang likes this.
  6. wang

    wang Well-Known Member

    The very last value when creating a Template Modification says Add-on: Click on the drop down list, select the name of the add on that you have created, and click the Save Template Modification button.
     
    Dadparvar likes this.
  7. Dadparvar

    Dadparvar Well-Known Member

    Thanks a lot @wang
    Successfully Created my first add-on ;)
     
    wang likes this.
  8. wang

    wang Well-Known Member

    You are most welcome. And congratulations with your first add on sir :)
     
    Dadparvar likes this.
  9. Dadparvar

    Dadparvar Well-Known Member

    Thanks for your kindness.

    This template modification is about to change the CTA portal page layout to Grid view.
    2016-01-09_01-55-51.png
    That @Gemma Taught me (in fact she did it. I just copied and pasted the codes. She made it). And I just made her tutorial as an add-on.
    I'll share it as she let me. Although she Taught me in a public thread that you can see it.
     
    Last edited: Jan 9, 2016
    wang likes this.
  10. wang

    wang Well-Known Member

    I am glad that I could be of help :)

    I get an error message when I opened that link. Most likely it is closed to guests.
     
    Dadparvar likes this.
  11. Dadparvar

    Dadparvar Well-Known Member

    Oops! Sorry. Thats right. That is for those who opted in xenforo forum there. Its free.
     
  12. 0ptima

    0ptima Well-Known Member

  13. Gemma

    Gemma Well-Known Member

    Joe Link and Dadparvar like this.
  14. Dadparvar

    Dadparvar Well-Known Member

    Sure.

    So nothing will be shared by me.

    Thanks
     
  15. Dadparvar

    Dadparvar Well-Known Member

    @wang
    Would you please letting me know how to add an option to "Option" of ACP, then associate it to newly created add-on?
    I want to Create an option that there is filed in it, where user can write HTML (better if be able to have editor there) on it, and then show its content somewhere in a template.
    I understood how to create add-on and associate a template modification with that add-on, but how to read the content from a field in option (instead of writing directly in find field while modifying a template)? I want to have that field so that each time that we want to edit the content, easily edit the filed in option, in stead of editing the template modification.

    I created an option group and associated it with the add-on.
    Then I can add options for it.
    Now what?

    Thanks in advance
     
    Last edited: Jan 13, 2016
  16. wang

    wang Well-Known Member

    Hello Dadparvar. Yes of course. You can use an option in templates, or in the template modifications, with this code,

    HTML:
    {$xenOptions.optionName}
    optionName should contain the actual name of your own option that you have created.
     
    Dadparvar likes this.
  17. Dadparvar

    Dadparvar Well-Known Member

    Worked.

    Thanks a lot. But how I can show a bigger field there? Now it shows a single line field.
    EDIT: found. by adding "rows=5" in "Format Parameters".

    And is it possible to use editor there? (Also HTML is not supported)

    Thanks a lot
     
    Last edited: Jan 13, 2016
  18. wang

    wang Well-Known Member

    You are welcome.

    To support html you can use this code.

    HTML:
    {xen:raw $xenOptions.optionName}
    To use the editor in options and to get it parsed, would need more extra code. You must have your view file where the editor code is parsed to be displayed correctly.
     
    Dadparvar likes this.

Share This Page