Expand my Community achievements bar.

Getting User-Agent Header in Sightly?

Avatar

Level 3

Hello all!

I need to do some workarounds for Microsoft products, and to do that I need to know the User-Agent in slightly, and do something different in the template if the User-Agent is 'ms-office'.

I've never been able to figure out how to use methods on the 'request' global object that require parameters.

I'm trying to do something like this:

${request.header @ name='User-Agent' }

but, that's not working.

I've seen examples like this:

${request.requestParameterMap['test'][0].toString}

...but that requestParameterMap method doesn't require any arguments...it returns an array, which is getting sub-selected in the expression.

There isn't a method on the 'request' object that returns all of the headers and their values that I can use this way.

I can create a whole java/js backer file just to get this one variable in this one case, but that seems way overkill compared to just passing in the name of the header that I need.  Especially since the request object is already in scope?

Thanks!

Tim

0 Replies