feincms/feincms — Issue #235: Make it possible to use different content templates for different regions
Author: i-trofimtschuk
Created: 2011-12-10 16:12:47+00:00
State: open

This is more an Idea for an improvement than an Issue/Bug.

For some content types (section for example) it would be nice to use different templates depending on the region the content type is contained in.
For now you can only restrict a whole content type to a region, not the some special TYPE_CHOICES of it:

Page.create_content_type(SectionContent, cleanse=True,
TYPE_CHOICES=(
(u'big_pic', _(u'For Main')),
(u'small_pic', _(u'For Sidebar')),
),
regions=('sidebar_region','main_region',))

This has the disadvantage, that if the user chooses the "wrong" one it could crash the design of the page.

I see two possible solutions:

The first is: Extending TYPE_CHOICES like this:

Page.create_content_type(SectionContent, cleanse=True,
TYPE_CHOICES=(
(u'main', _(u'Main'), ('main_region',)),
(u'sidebar', _(u'Sidebar'), ('sidebar_region',)),
))
This would allow ro register some types for some regions only
=> Disadvantage: API-Changes

The other solution could be a convention for the templates like it is done in mediafile/section using the type. For example the section content types render method could be changed from

def render(self, **kwargs):
if self.mediafile:
mediafile_type = self.mediafile.type
else:
mediafile_type = 'nomedia'
return render_to_string([
'content/section/%s_%s.html' % (self.type, mediafile_type),
'content/section/%s.html' % self.type,
'content/section/%s.html' % mediafile_type,
'content/section/default.html',
], {'content': self})

to something like this:

def render(self, **kwargs):
if self.mediafile:
mediafile_type = self.mediafile.type
else:
mediafile_type = 'nomedia'
return render_to_string([
'content/section/%s__%s_%s.html' % (self.region, self.type, mediafile_type),
'content/section/%s_%s.html' % (self.type, mediafile_type),
'content/section/%s__%s.html' % (self.region, self.type),
'content/section/%s.html' % self.type,
'content/section/%s.html' % mediafile_type,
'content/section/default.html',
], {'content': self})