kmh wrote:
>>On 10/20/05, kmh <[EMAIL PROTECTED]> wrote:
>>
>>>Shouldn't we encourage a model where site templates are able to
>>>explicitly "include" application templates, rather than the other way
>>>around?
> 
> 
>>On 10/20/05, Sune Kirkeby <[EMAIL PROTECTED]> wrote:
>>That's not how applications and templates work. You can't just
>>include a template from another application, you would be missing
>>the context that the application views provide.
> 
> 
> A more "include" oriented solution would be to let sites rather than
> applications determine which site base template is being extended by an
> application template.  I have just discovered the {% extends variable
> %} tag, which seems to fit this bill.  It should also be encouraged
> that application features that don't depend on the request be made
> templates tags rather than views.
> 
> Kieran
> 
> 

I think what you actually want is for applications to provide you with
template tags that encapsulate most of the functionality of thier views.

Then in your site template, you can compose these template tags to your
hearts content.

Maybe this should be a best practice too?

This is very easy with the @inclusion_tag decorator in #625.
(Predicated on 625 being applied (cough...Adrian...cough) , or using
new-admin branch.)

Should I add this to the wiki page?
-------------------------
Parts of your application that may be useful embedded in site views
should be structured as template tags.

Create a template of just the portion of your view that is reusable:

poll/results_panel.html:

<div class="poll-panel" >
   <h3> {{poll.name}} </h3>
   <ul>
   {%for choice in poll%}
      {{ choice}} : {{choice.votes}}
   {%end for%}
   </ul>
</div>

create a template tag using this template,
polls/templatetags/polls.py

@inclusion_tag('poll/results_panel.html')
def results_panel(poll):
    return {'poll': poll}


In your views and site views, use the template tag:
{% load polls %}
{% results_panel poll %}


Sites can override the poll/results_panel.html template to customise
this. It will apply sitewide, including within the app within which the
template tag resides.

(It is of course possible to do this without using @inclusion_tag, but
it is a pain.)

-------------------------------

This seems like a pretty good pattern to me, especially for apps to
provide little summary views for aggregation by sites.

Reply via email to