You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
xiongchiamiov edited this page Dec 9, 2014
·
2 revisions
reddit's templating system is a bit less direct and explicit than some other systems. Here's a very high-level overview:
At some point in time, a class is constructed and .render() called on it. There are many of these classes, but what you'll find in common between them is that they inherit, directly or indirectly, from Templated. Here's an example:
class PasswordChangeEmail(Templated):
"""Notification e-mail that a user's password has changed."""
pass
You'll note there is absolutely no body to the class; how then does it change functionality at all? The answer lies in some meta-magic in Templated's constructor, which stores self.__class__ as the render class.
One more thing: since it's common to want to render the same data a number of ways (desktop-oriented HTML, mobile web, JSON, etc.), there's a mapping of extensions that force rendering to happen with a particular style. So if you tack on .compact to a url, it will render with whatever.compact instead of whatever.html, without you having to write code to switch based on that.