Ticket #13984: 0002-template_name-as-optional-return-value-of-django.temp.diff
File 0002-template_name-as-optional-return-value-of-django.temp.diff, 1.8 KB (added by , 14 years ago) |
---|
-
django/template/loader.py
185 185 context_instance = Context(dictionary) 186 186 return t.render(context_instance) 187 187 188 def select_template(template_name_list ):188 def select_template(template_name_list, return_template=False): 189 189 "Given a list of template names, returns the first that can be loaded." 190 190 for template_name in template_name_list: 191 191 try: 192 return get_template(template_name) 192 if return_template: 193 return get_template(template_name), template_name 194 else: 195 return get_template(template_name) 193 196 except TemplateDoesNotExist: 194 197 continue 195 198 # If we get here, none of the templates could be loaded -
docs/ref/templates/api.txt
525 525 the template with the given name. If the template doesn't exist, it raises 526 526 ``django.template.TemplateDoesNotExist``. 527 527 528 .. function:: django.template.loader.select_template(template_name_list )528 .. function:: django.template.loader.select_template(template_name_list, return_name=False) 529 529 530 530 ``select_template`` is just like ``get_template``, except it takes a list 531 531 of template names. Of the list, it returns the first template that exists. 532 If the optional argument return_name is set to True, it will also return 533 the selected templates name. 532 534 533 535 For example, if you call ``get_template('story_detail.html')`` and have the 534 536 above :setting:`TEMPLATE_DIRS` setting, here are the files Django will look for,