Am 20.04.2012 09:00, schrieb Sam:
Any advice on overriding expose to allow for the mobile template to be
explicitly named. And then doing the detection of whether the browser
is mobile or not?

The standard expose() decorator has an accept_format parameter which allows choosing a different template based on the accept request header.

You could write a decorator that takes another parameter for choosing a template based on other criteria like cookie values, but it's difficult.

Maybe the simplest solution would be to make the template parameter callable. In that case the parameter would be called and the return value taken as the template name. It's a simple enough feature to add it to TG 1.5. We're using this idea in several other places already, and it would allow for a lot of flexibility. In the callable you can make all kinds of case distinctions using the cookies or any headers from the cherrypy.request. I just tried that and it works nicely.

Anybody against such a change? Maybe this would be useful for TG2, too?

Is there some other way I should be doing this?

You can alter the template dynamically in the controller like this:

http://turbogears.org/1.5/docs/ExposeDecorator.html#dynamically-switching-templates-within-a-function

-- Christoph

--
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en.

Reply via email to