HTTP Request Headers in display templates

Options

I noticed that we can now access request headers in our templates. This will go a long way to solve a lot of IE6 problems that I've been having. Could someone at Convio please post the syntax here for everyone's reference?

Thanks.

Tagged:

Comments

  • First off, let me apologize for not having the documentation updated yet. My hunch is that you'd rather get your hands on the feature early... but it's no excuse. We're working on it.

    As far as how to access the request headers, let me explain. There is a new "object" in the templating system called "header". If you display it like this:



    <t:value id="header">I wonder what shows up here</t:value>

    You will see all the headers as a string. Nice, but not very useful. To get at a single header, you can do this:



    User-Agent: <t:value id="header.User_Agent">the user agent will appear here</t:value>!

    Note: all hyphens in header properties are converted to underscores, so the header property "User-Agent" is referred to as "User_Agent".

  • Bruce Keilin:

    First off, let me apologize for not having the documentation updated yet. My hunch is that you'd rather get your hands on the feature early... but it's no excuse. We're working on it.

    As far as how to access the request headers, let me explain. There is a new "object" in the templating system called "header". If you display it like this:



    <t:value id="header">I wonder what shows up here</t:value>

    You will see all the headers as a string. Nice, but not very useful. To get at a single header, you can do this:



    User-Agent: <t:value id="header.User_Agent">the user agent will appear here</t:value>!

    Note: all hyphens in header properties are converted to underscores, so the header property "User-Agent" is referred to as "User_Agent".

    Hi Bruce,

    Thanks a lot for getting back so quickly on this. I'm working with the syntax now and it is going to work great for getting around some of these IE6 issues.

    I do have another question. When I try to use the matches() function to test the user_agent string, my regex is constantly erroring whenever I user escaped characters: \\s \\. etc. Is the implementation of regex in the matches() function comprehensive or limited to just wildcards?

    Thanks.

  • mark.ajws :

    Hi Bruce,

    Thanks a lot for getting back so quickly on this. I'm working with the syntax now and it is going to work great for getting around some of these IE6 issues.

    I do have another question. When I try to use the matches() function to test the user_agent string, my regex is constantly erroring whenever I user escaped characters: \\s \\. etc. Is the implementation of regex in the matches() function comprehensive or limited to just wildcards?

    Thanks.

    Just "." and "*" are supported. If you want to match anywhere in a string, use:



    <t:if test="matches('This is a sentence about dogs and cats!', '.dogs.')">

    To match "cats!" at the end of the string:



    <t:if test="matches('This is a sentence about dogs and cats.', '.*cats!')">
  • Bruce Keilin:

    Just "." and "*" are supported. If you want to match anywhere in a string, use:



    <t:if test="matches('This is a sentence about dogs and cats!', '.dogs.')">

    To match "cats!" at the end of the string:



    <t:if test="matches('This is a sentence about dogs and cats.', '.*cats!')">

    Thanks for clarifying this. You should update this information in the template reference as currently it advises users to look at the complete regex reference for help while really only two operators out of dozens are supported. Hopefully future upgrades will enable the full regex syntax to be leveraged.

  • mark.ajws :

    Thanks for clarifying this. You should update this information in the template reference as currently it advises users to look at the complete regex reference for help while really only two operators out of dozens are supported. Hopefully future upgrades will enable the full regex syntax to be leveraged.

    Good point. I've transcribed your comments onto a box of chocolates and placed them on our documentation writer's desk. Metaphorically, at least.

  • I was just going to ask about this feature. It could be useful for create an iPhone specific version of the site.

  • Seamus Leahy:

    I was just going to ask about this feature. It could be useful for create an iPhone specific version of the site.

    That's exactly what I had in mind when I wrote it. Please share the fruits of your efforts. I have a feeling more and more people will be interested in this in the near future.

Categories