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

What is more efficient? Template include or hard coded into template?

Discussion in 'XenForo Questions and Support' started by steven s, Dec 11, 2010.

  1. steven s

    steven s Well-Known Member

    For instance.
    We can either create a template and add to say, PAGE_CONTAINER using <xen:include template="template_name" /> or
    add directly to PAGE_CONTAINER.

    On one hand it's less to edit when reverting templates when using include template.
    On the other hand, does it take longer to render the page using the include?

    6 of 1, 1/2 dozen of another?
    Is one better coding practice over the other?
    Whatever floats your boat?
     
  2. Kier

    Kier XenForo Developer Staff Member

    It makes no difference whatsoever - all template includes are resolved at save time, not run time.
     
  3. Brogan

    Brogan XenForo Moderator Staff Member

    I always use an include as it keeps the main templates tidier and it just seems like better practice.

    In the same way that I don't do inline styling but use separate stylesheets.
     
    CFodder and EQnoble like this.
  4. steven s

    steven s Well-Known Member

    Good to know.
    Tidier is good.

    Regarding inline styling. You would not use <div style="text-align: center;"></div> but rather place the CSS in EXTRA.css?
    Any reason, or just tidier also?
     
  5. Brogan

    Brogan XenForo Moderator Staff Member

    Just to keep it tidy and also make it easy to locate/change in the future.

    I give each entry in EXTRA.css a short description so I know what it's for.
    For example:
    Code:
    /* Move search box */
    #QuickSearch {
    right: 10px;
    }
    
    /* Make URL links in posts bold */
    .ugc a {
    font-weight: bold;
    }
    
    /* Change colour of the primary button */
    .button.primary {
    background-color: @secondaryLighter;
    }
     
  6. ragtek

    ragtek Guest

    why extra.css?*g*

    If you have own templates, i would also use own css templates;)
     
  7. steven s

    steven s Well-Known Member

    OK, OK. Just askin'. :)
     
  8. Brogan

    Brogan XenForo Moderator Staff Member

  9. ragtek

    ragtek Guest

    Yes, but if you put all you're own elements into the extra.css, which aren't needed global, it will blow it up unnecessary;)
     
  10. Brogan

    Brogan XenForo Moderator Staff Member

    Most of them are required for every page view, such as the search box.
    Besides, it's only about 50 lines in total.
     
  11. steven s

    steven s Well-Known Member

    OK, so if the CSS is used say only in the sidebar it makes more sense to code the css within the template.
     
  12. EQnoble

    EQnoble Well-Known Member

    I don't know if my logic is correct here but this is what I have been doing...

    adding my css rules to a new template as to be able to edit that specific entity in the admin panel by isolating that specific set of styling rules in the way of as brogan put it 'tidiness'.

    Then if the case at hand is CSS I would do a <xen:include template="mynew.css" />in the xenforo.css template to call it all together. It works for me as sometimes I use DW but for the most part I'm either editing templates directly in the admin panel or over ftp, editing documents which for me opens up WIN notepad.exe (HA shut off text wrap) so personally speaking... easily finding modifications I have made is essential as I am NOT a coder.

    I suppose I could try using the extra.css as (unless i'm to stand corrected) it gets included on every page.

    Question: would this work...

    make new template { newcss1.css} --- add my code
    throw a --> <xen:include template="newcss1.css" /> in the extra.css template

    ...to include custom styling on every page?
     
  13. Kier

    Kier XenForo Developer Staff Member

    Adding custom_template.css to support custom_tempate and then referencing it with <xen:require css="custom_template.css" /> is precisely how the system is intended to be used.
     
    EQnoble likes this.
  14. EQnoble

    EQnoble Well-Known Member

    Kier could you possibly re-word "to support custom_template" I'm just a little out of it right now and I think your saying when I make a custom template "this_template" I would make a corresponding "this_template.css" and do the xen:require css in the "this_template"
     
  15. Brogan

    Brogan XenForo Moderator Staff Member

    The template names are not related at all.
    You just reference each one using either: <xen:include template="" /> or <xen:require css="" />

    So in your custom template you would add <xen:require css="" />

    In an existing template you would add <xen:include template="" />
     
    EQnoble likes this.
  16. EQnoble

    EQnoble Well-Known Member

    ahhha gotcha
    thank yah
     
  17. EQnoble

    EQnoble Well-Known Member

    Ok now I have a question that I can't derive an answer from.

    I redid my xxmP BBcode which requires template edits and using the exact same setup as before on a clean installation sans the edit of the xen:include to xen:require for the css additions and it broke the code...by replacing it back to :include the code instantly worked again.

    what am I doing wrong... lol
     

Share This Page