On Mon, 2008-02-11 at 16:55 -0800, Peter wrote:
> I have a bunch of widgets that I access dynamically and they render
> their own parts of a page.  I would like to give these widgets the
> ability to use templates.  Furthermore, these are not installed apps,
> so I do not have access to the
> "django.template.loaders.app_directories.load_template_source" loader
> type.
> 
> So the widgets are like this:
> 
> project/
>   |_widgets/
>        |_widget1/
>        |_widget2/
> 
> I initially decided to just make a templates directory in this
> "widgets" folder where each widget could add its own folder of
> templates -- sounds reasonable.
> 
> However, I'm curious about... What if I let these widgets put
> templates directly in their own folders and I declare that project/
> widgets is a template directory?  This seems a bit blasphemous, but
> ideologies aside -- are there computational issues with this approach
> (e.g. longer search for resolving templates, strange conflicts?)

Just do it. There's no problem here. TEMPLATE_DIRECTORIES is just a list
of directories that is searched by the filesystem loader for files that
match the name you want to load. So the only drawback is that those
directories are searched every time you load a template. Might be an
issue, might not be.

Alternatively, if you want to super-efficient and tricky, your widgets
could load their template strings manually: you can pass a "dirs"
argument to the find_template_source() function, so you could manually
alter the directories to search when loading the templates. Using a
combination of find_template_source() and get_template_from_string(),
just as get_template() does, means you can create a Template object
instance, loading the source from a restricted, custom set of
directories. Have a poke around in django/templates/loader.py for
details.

Regards,
Malcolm

-- 
The only substitute for good manners is fast reflexes. 
http://www.pointy-stick.com/blog/


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to