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

How to extend XenForo_Template_Public::getRequiredCssUrl

Discussion in 'XenForo Development Discussions' started by Marcus, Feb 23, 2015.

  1. Marcus

    Marcus Well-Known Member

    I want to manipulate the return value of XenForo_Template_Public::getRequiredCssUrl , how could I do that? The load_class listener does not work. And I am not sure which template I should manipulate to manipulate the return value of that function. Thanks!!
  2. Xon

    Xon Well-Known Member

    You can't.

    The templating system doesn't really appear to be written with much interaction with the load_class listener framework, and makes heavy use of static methods & variables.

    Excluding code edits;

    The closest way, to achieve rewriting the Css Urls, is to use a post render template hook to zero out/replace the magic marker "<!--XenForo_Require:CSS-->". And then use tricks such as defining your own classes providing getters & setters for the protected static class members hidden deep in the templating system.
    Marcus likes this.
  3. Mr. Goodie2Shoes

    Mr. Goodie2Shoes Well-Known Member

    Actually there's an 'ugly' way by porting into Autoloader to extend the class XenForo_Template_Public which I use to extend the exact same method. I created that autoloader myself, you can use https://github.com/Yoskaldyr/cmf_core/ to do that :)
    Marcus and Xon like this.
  4. Marcus

    Marcus Well-Known Member

    Hi Xon!

    thanks so much for helping me understand the template system. So I guess to keep my code short I would have to do something like string_replace("css.php"...) which is faster than a regular expression.

    So maybe I will just do a simple file edit, I already have a small bash script that runs after every upgrade :D
    Xon likes this.
  5. Mr. Goodie2Shoes

    Mr. Goodie2Shoes Well-Known Member

    lol... that's another way :p
    Xon likes this.
  6. Xon

    Xon Well-Known Member

    @Mr. Goodie2Shoes's suggestion is probably easier IMO than first suggested solution.

    Another way is to manually include() a file edited copy (from index.php or config.php). The original XF file is untouched, and you just use your version.
    Luke F and Mr. Goodie2Shoes like this.
  7. Marcus

    Marcus Well-Known Member

    I learnt how to use sed and now I have a simple bash script that I execute after each upgrade. If if would also upgrade the file hashes, too so xenforo doesn't remind me of the changed files. It is really very easy to work with and I have all my file edits within that single bash script so it works as a simple file-change-documentation, too.

Share This Page