Templating PHP and quoting vars

Hi

I'm templating PHP configuration files, but having some issues trying
to make variables work that can be different types.
Take for instance this snippet of config that I'm trying to template:

    /*
     * Cookie domain.

I've come up with this custom filter:

def phpescape(var, quote='\''):
    """Escape a value based on it's type.
    This is usefull for templating PHP files, where you need to quote
    strings but not booleans/null/etc.
    """
    if isinstance(var, string_types):
        return quote + var + quote
    elif var is None:
        return 'null'
    return var

This way I can keep the template lines as simple as:

   'session.cookie.domain' => {{ session_cookie_domain | phpescape }},

This will do the right thing for strings, null, booleans, and integers.

Dick