page.render like tag

10 views
Skip to first unread message

Gabriel - Iulian Dumbrava

unread,
Jan 13, 2012, 1:30:45 AM1/13/12
to Django FeinCMS
Hi there,

I'm using FeinCMS for a few days now and I'm very pleased with the way
it works. I have added the ItemEditor to one of my models, but I run
into a small rendering problem.

I have a master page, for my Object where I display some information.
I have registered for my object two different templates one with 2
columns and one with 1 column, each being rendered by two different
templates, which according to the number of columns iterates through
content of each regions and displays them accordingly.

My problem is that I don't have (or find) a tag that I can use in the
master page to render the page content, which in turn should include
and render the corresponding chosen template.

For example, I want:
Object.title
Object.characteristic1
Object.characteristic2
---
Object.content -> this should be rendered by the 2 columns template
or 1 column template, according to which template I have chosen in
Admin.

Do you have something like {% Page.content.render %} ?

Thank you,
Gabriel

Matthias Kestenholz

unread,
Jan 13, 2012, 4:45:56 AM1/13/12
to django-...@googlegroups.com

Nothing like this exists currently. It should not be hard to write
this template yourself, though, something like this might do the
trick:


from django import template
from django.template.loader import render_to_string

register = template.Library()

@register.simple_tag(takes_context=True)
def render_object(context, object):
return render_to_string(object.template.path, {'object': object},
context_instance=context)


takes_context is not required but it might be useful.


Matthias

Gabriel - Iulian Dumbrava

unread,
Jan 13, 2012, 3:48:43 PM1/13/12
to Django FeinCMS
Thank you very much Matthias,

I've solved it even simpler after reading your answer:

{% include current_page.template.path with object=current_page %}

I don't know if this is the most elegant way, but it solves the
problem.

Gabriel

Matthias Kestenholz

unread,
Jan 16, 2012, 10:21:20 AM1/16/12
to django-...@googlegroups.com
On Fri, Jan 13, 2012 at 21:48, Gabriel - Iulian Dumbrava
<gabriel....@gmail.com> wrote:
> Thank you very much Matthias,
>
> I've solved it even simpler after reading your answer:
>
> {% include current_page.template.path with object=current_page %}
>
> I don't know if this is the most elegant way, but it solves the
> problem.
>

Of course! I think that's quite elegant :-)

No need to write a custom template tag with Django's improved {% include %} tag.


Matthias

Reply all
Reply to author
Forward
0 new messages