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

Get Cookie from within a template?

Discussion in 'XenForo Development Discussions' started by vord, Apr 9, 2016.

  1. vord

    vord Member

    Is it possible to check for a cookie from within a template? The cookie is set based on visitor preferences and I just want to check if it exists.

    In PHP I would write:
    Code:
    if(isset($_COOKIE["preferences"])) {
    // insert javascript code here
    } else {
    // insert different javascript code here
    }
    If it is not possible to access cookies within the template could anyone point to an easy way to do it without editing files that I might overwrite when I upgrade?
     
  2. James

    James Well-Known Member

    Just insert your javascript into the template to check for a cookie via js?
     
  3. vord

    vord Member

    I want to include different javascript based on visitor preferences (the javascript in question being a Google ad).

    I don't think I can do that using the javascript method of getting cookies without messing around with the ad code which I'm not supposed to do.
     
  4. vord

    vord Member

    I think I've fixed it by using a callback to a php file. It was probably also possible in javascript but I'm not all that good at that.
     

Share This Page