Fourms Products

Go Back   KXDesign > Programming Discussion > Tutorials > [vBulletin|PHP|HTML]Avoid Template Edits

Tutorials Post all tutorials regarding programming,design or vBulletin here!

Reply
 
Bookmarks Thread Tools
Old 15-08-2008   #1 (permalink)
KXDesign Admin
 
Komplex's Avatar
 
A Little About Komplex
  • Join Date: Jul 2008
  • Location: Slovakia
  • Posts: 163
  • Rep Power: 5 Komplex is infamous around these parts
  • Send a message via MSN to Komplex
    Lightbulb [vBulletin|PHP|HTML]Automatic Template Edits

    You are creating a new vBulletin product and want to make it more user friendly so that the users don't have to edit the templates manually?Then this tutorial will point you the right way.Basically the code I am going to demonstrate simply finds a specific part of a template and inserts our code/template into it.

    Ok let's say you have a template or a piece of html code you want to include somewhere:

    HTML Code:
    Unregistered users can not view codes.Please register.
    
    Ok now we have to options:

    1. Insert the code into a template and then insert the whole template into the site.


    So you now have the html code in your template called TEMPLATE.I suggest you cache it for faster loading.To do that create a new plugin on the cache_templates hook with this content:

    PHP Code:
    Unregistered users can not view codes.Please register.
    $globaltemplates variable are the templates that are supposed to be cached.It is an array because it contains multiple templates,default ones and the ones from other 3rd party products.

    So now what we just need to do,is insert our template into another one.To do that you need to know what page you want to display it on,the hooks that are located on that page and the templates called.In the template you will add the code in find a block of code that is static,thus won't ever be changed (like html comments).Should be one liner.Our template is TEMPLATE and the one that will include it is MAINTEMPLATE.

    Then use this phpcode.

    PHP Code:
    Unregistered users can not view codes.Please register.
    Explanation: the template MAINTEMPLATE is represented by the variable $vbulletin->templatecache['MAINTEMPLATE'].So we changed the way it is represented.We used str_replace to change the MAINTEMPLATE,so now it added the TEMPLATE into it.It searched for $variable and attached the template into it.

    To include a code on every page use the hook global_start and the template header,footer or headinclude

    DONE




    2. Insert the code into a variable and insert it via replace.


    Ok this is a bit easier than the code above.So we still want to add the code but don't want a template?Make the code into a variable.

    PHP Code:
    Unregistered users can not view codes.Please register.
    we used ' apostrophes instead of " so that the code isn't parsed directly in the variable but rather in the template.Note,if you have ' or " in your code,you have to put \ before them so that php doesn't think it belongs into the main code.

    Then just use the code before.


    PHP Code:
    Unregistered users can not view codes.Please register.
    DONE


    3. Insert the code into a variable and call the variable in the template.


    This is the easiest way.So we have $template already specified and we just put the variable ($template) into any template and vBulletin will parse it .But you have to make sure that the hook the variable is on,is called on that page!
    DONE


    4. Attach code to an existing variable in the template.

    This method became easier when vBulletin introduced template hooks. For instance,open template navbar and you can find $template_hook['navbar_buttons_left'] somewhere in the code,thanks to which you can add new navbar buttons simply using plugins.To do that,I make a new plugin on global_setup_complete (or any plugin called where the variable is) and add this code:

    PHP Code:
    Unregistered users can not view codes.Please register.
    See the ".=" ?That means that the code following it was added to the variable's value and thus displayed when the variable is parsed .

    You can also attach a whole template this way.In the next example I added my template below navbar.

    PHP Code:
    Unregistered users can not view codes.Please register.
    DONE

    I hope this article has helped you understand this topic and develop better and more user friendly products!
    __________________
    .::{KXDesign Owner}::.
    Komplex is offline   Reply With Quote
    Old 22-02-2009   #2 (permalink)
    New Member
     
    A Little About itsheinz
    • Join Date: Feb 2009
    • Posts: 3
    • Rep Power: 0 itsheinz is an unknown quantity at this point
    Default Re: [vBulletin|PHP|HTML]Avoid Template Edits

    Nice tutorial
    itsheinz is offline   Reply With Quote
    Old 12-08-2009   #3 (permalink)
    New Member
     
    A Little About sunnych
    • Join Date: Jul 2009
    • Posts: 1
    • Rep Power: 0 sunnych is an unknown quantity at this point
    Default Re: [vBulletin|PHP|HTML]Avoid Template Edits

    that works well on global
    __________________
    Dental insurance
    Ge mwf
    MoneyTec
    sunnych is offline   Reply With Quote
    Old 16-08-2009   #4 (permalink)
    New Member
     
    A Little About rokdave
    • Join Date: Aug 2009
    • Posts: 1
    • Rep Power: 0 rokdave is an unknown quantity at this point
    Default Re: [vBulletin|PHP|HTML]Avoid Template Edits

    well thank for the further info i learn something new about how to avoid Template Edits


    _________________
    Indianapolis seo
    rokdave is offline   Reply With Quote
    Old 1 Week Ago   #5 (permalink)
    New Member
     
    A Little About Heildewsslups
    • Join Date: Dec 2009
    • Location: Luxemburg
  • Posts: 1
  • Rep Power: 0 Heildewsslups is an unknown quantity at this point
  • Send a message via ICQ to Heildewsslups
    Default Watch free p0rn 0nline n0w3

    Watch free p0rn 0nline n0w6
    Extreme free forn galleries and movies! Enjoy!



    Watch free p0rn 0nline n0w3
    Heildewsslups is offline   Reply With Quote
    Reply


    Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
     
    Thread Tools

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off
    Trackbacks are Off
    Pingbacks are Off
    Refbacks are Off



    All times are GMT +1. The time now is 03:41.


    Content Copyrighted To KXDesign© 2008-2009
    Powered by vBulletin® Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
    SEO by vBSEO 3.2.0