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

XF 1.2 Custom Template Variable

Discussion in 'Styling and Customization Questions' started by katsulynx, Aug 28, 2013.

  1. katsulynx

    katsulynx Well-Known Member

    Is there a way to use a custom variable in the xenforo templates? I want to implement a background changer with a picture url stored into a cookie. Currently I am changing the background picture with jQuery every time the page is loaded but this is more than inefficient.

    Best way would be to store the cookie value somewhere in the templates into a variable like the font-colors and then be able to open it in css whereever needed with something like '@background' or so. Is this possible?
  2. katsulynx

    katsulynx Well-Known Member

    As nobody seemed to know if it is possible or not, I tried to do a workaround with the callback function. It may not be as pretty as defining the variable once and use it wherever needed, but it works... mostly. The callback is set up to return the variable of the cookie if existing, if not, the standard background url. Unfortunately, it does not seem to recognize my cookies...

    Is callback able to handle cookies or not?
    Callback looks like this:

    class Mycallback_Background {
        public static function 
    getBackground() {
            if (isset(
    $output $_COOKIE['background'];
    $output "styles/kitsunebi/xenforo/kitsunebi_IMG/background.png";

  3. katsulynx

    katsulynx Well-Known Member

    Still noone to help? :(

    I figured out cookies are working but it takes time for the callback to update and refresh. So everytime I change the cookie I have to wait until the change is recognized by the callback. This takes time up to 15 minutes. Is there a way to make the callback update more often or maybe really to create a template variable?
    Last edited: Aug 28, 2013

Share This Page