Mod to allow simple_tag to access context
This is a mod I made to the Django simple_tag system to let the simple_tags access comments. I plan to try and get it integrated into the trunk, so it's mainly here so (a) the people on django-developers can see it, and (b) while I'm waiting, or if it doesn't get put in the trunk, people can use it. **Installing** 1. Open the module `django.template.__init__`, wherever that lives. 2. Scroll down to the beginning of " `class Library:` " 3. Find the simple_tag function (" `def simple_tag(self,func):` ") 4. Replace the function (even the whitespace before each line) with the code snippet. **Usage** 1. When defining a simple tag (see the [docs](http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#shortcut-for-simple-tags) for more info), have the first parameter in your function be named "`context`". Otherwise, an error will be thrown. It can accept other parameters like normal. 2. Use `register.simple_tag(my_function_name, takes_context=True)` to register your function as one that will use the context. 3. The tag's function can access the context like a dictionary - to get a value, just use `context['cheese']`, or to set one, use `context['cheese'] = 'Limberger'`. Due to the context's mutability, this will affect the context in the main template as well. **Notes** This code hasn't been tested in a "production environment", but I did test my modifications thoroughly, and if you don't add `takes_context=True`, `simple_tag` will behave exactly as normal. Of course, if there is a problem, make sure you leave a comment. **Code** Since most of the code is hacked up from other Django library functions, and to prepare for if and when it's merged into the trunk, it's released under the BSD license.
- template
- template-tags
- template-engine