Hi Jay,

On Tue, 2006-05-16 at 17:24 -0400, Jay Parlar wrote:
> As an example, say I'm building a blogging app, and I want a right
> sidebar that always shows the last X post titles. What's the best way
> to template this?
> 
> I've though of something like the following in a base.html:
> 
> <div id="sidebar">
> {% block sidebar %}
> {% last_posts_list %}
> {% endblock %}
> </div>
> 
> Where 'last_posts_list' is a templatestag that I write myself. Then
> all my real pages that inherit from base.html will get that
> dynamically generated content in the sidebar.
> 
> Somehow though, that solution feels a bit too "heavy". I'm a Python
> programmer by trade, so I don't mind having to write a custom template
> tag, but I keep seeing all this talk of non-programmers doing
> wonderful things very easily, so it feels like I'm missing something
> basic here.
> 
> It feels like I should be able to define a template just for the
> sidebar, and insert the content of that template into whatever
> template is being rendered. I guess that the 'include' tag would do
> that, but then I'd need to explicitly pass the required sidebar
> context into every template, right?

I think your intuition is right on both counts here. Your solution is a
bit more heavyweight than what most people are doing, but your
requirements are a bit stricter, too, so it's OK. Either you need to put
the data in the context for the template tags (as "include" wants you to
do), or you need to write a smart template tag that gets the data itself
and behaves more transparently. Both approaches are valid, so don't
overthink it too much. :-)

I personally use the "put the data in the context" approach, but my
sidebars sometimes vary a little based on location and the view
functions know about my location, whereas the templates and template
tags don't (since I'm reusing templates for many views).

Best wishes,
Malcolm


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to