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

Can someone explain this in a bit more detail?

Discussion in 'XenForo Development Discussions' started by BamaStangGuy, Oct 18, 2012.

  1. BamaStangGuy

    BamaStangGuy Well-Known Member

  2. xfrocks

    xfrocks Well-Known Member

    You can always ask me :D

    Anyway, the idea is adding a event listener for init_dependencies, something like this:

    PHP:
    XenForo_Template_Helper_Core::$helpers['bamastangguy_ucwords'] = 'ucwords'
    Then in the template, just use it like this:

    Code:
    {xen:helper BamaStangGuy_ucwords, $tag.tag_text}
    Notice
    • The lowercase in $helpers['bamastangguy_ucwords'] is required
    • The mixedcase in {xen:helper} is not required, you can use bamastangguy_ucwords or bAmAsTaNgGuY_uCwOrDs or anything in between.
    • This code is not tested :D
     
    Walter, Jake Bunce and BamaStangGuy like this.
  3. BamaStangGuy

    BamaStangGuy Well-Known Member


    Thanks, I didn't want to bug you too much. You've been very helpful.
     
  4. BamaStangGuy

    BamaStangGuy Well-Known Member

    Bump, I never got around to looking too much into this. With the latest updates I'd like to take a stab at it again (i hacked my copy on one site a lot and would rather do it right with the update). Anyone with more knowledge than me care to take a stab at making this happen? Where would I actually put this code?
     
  5. Brandon Sheley

    Brandon Sheley Well-Known Member

  6. BamaStangGuy

    BamaStangGuy Well-Known Member

    That seems like a lot of work just to ucwords one variable :confused:
     
  7. BamaStangGuy

    BamaStangGuy Well-Known Member

    Well I took a shot at this and still can't get it to ucwords the title tag.

    Code:

    Helpers.php
    PHP:
    <?php
    //Our class helper (we can put any helpers in here we want)
    class UcWords_Helpers
    {
        public static function 
    ucWords($string)
        {
            
    //We only return the argument, dont do nothing.
            
    return $string;
        }
    }
    Listeners.php
    PHP:
    <?php
    //Our class name
    class UcWords_Listener
    {
        public static function 
    init(XenForo_Dependencies_Abstract $dependencies, array $data)
        {
            
    //Get the static variable $helperCallbacks and add a new item in the array.
            
    XenForo_Template_Helper_Core::$helperCallbacks += array(
                
    'ucwords' => array('UcWords_Helpers''ucWords')
            );
        }
    }
    Event Listener:
    Screen Shot 2013-03-05 at 5.42.57 PM.png
     

Share This Page