Hello,

On Jan 28, 2008 3:09 PM, theZero <[EMAIL PROTECTED]> wrote:
>
[introduction]
>
> Pages are called using select_related(), which retrieves the
> associated Pods. So in the template, I have several areas like this:
>
> {% block leftcolumn %}
>     <div id="left_column">
>     {% for pod in page.pods.all %}
>         {% ifequal pod.placement "left" %}
>         <div class="pod">
>         <h2>{{ pod.Title }}</h2>
>         {{ pod.Content|escape|linebreaks }}
>         </div>
>         {% else %}
>         {% endifequal %}
>     {% endfor %}
>     </div>
> {% endblock %}
>
> It works, but I definitely know it's not the best way to do it. I have
> two primary problems with it.
>
> First, if there are no items in that block, then I don't want to show
> that <div id="left_column"> on the page at all. How can I choose to
> display the contents of a block depending on if a pod exists that
> meets the select criteria? I know I'm missing something simple, but I
> can't put my finger on it.

If I am not mistaken, {% if page.pods.all %} should evaluate to False
if there are no pods, so you can enclose your <div> with that and it
should work as you'd like.

> Second, it is obviously and woefully inefficient to do this for
> several blocks on the page. I may have 5 or more, and I may want to
> add some in the future. Is this the place for a custom templatetag?
> Has someone already put something like this together?
>
> If I'm completely off-base and thinking about this wrong, let me know.
> I'm still learning!

I have no experience with this second issue. Sorry!


Hope it helps,
Eduardo.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
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