Page 1 of 1
Featuring a variety of content in a CMS
Posted: Fri Jun 05, 2009 12:47 am
by allspiritseve
I come across situations once in a while where I want to treat different types of content the same way. For example, in the current site I'm doing a client has requested to be able to feature both pages and images from her gallery in the same box on her homepage. (We currently only have the capability to feature pages). My first thought was to have both Page and Image classes implement a Featurable interface. However, I'd like the possibility of the feature text to be different from the standard content, so that means I'd have to use method names that would never be used on any content item in the future

. Also, if I'm pulling information for a feature, I really only need a title, description, image, and link-- the rest of the content would be loaded unnecessarily. So now I'm thinking of making a separate class called Feature that can be generated when editing a page or image-- or edited separately. Does that sound like it would work? What do other people do when needing to treat different content types the same way?
Re: Featuring a variety of content in a CMS
Posted: Sun Jun 07, 2009 1:10 pm
by alex.barylski
I'm not sure I fullly understand the problem...but I assume your using MVC of some sort?
In which case it should be trivial to have two different views pull on the same model...but that doesn't sound like the issue your having...
Can you give breif code examples maybe?
Re: Featuring a variety of content in a CMS
Posted: Sun Jun 07, 2009 1:29 pm
by allspiritseve
PCSpectra wrote:it should be trivial to have two different views pull on the same model
More like the same view pull on a collection of different domain objects.
Here's an example I pulled from one of our sites:
Code: Select all
<?php foreach ($features as $feature): ?>
<td valign="top" class="feature"><?php if($feature->getImage()): ?>
<div class="featurephoto"><a href="<?php echo $feature->getUrl(); ?>"><img src="userfiles/image<?php echo $feature->getImage(); ?>_small.jpg" alt="" width="120" border="0"/></a> <br clear="all">
</div>
<?php endif; ?>
<h3><a href="<?php echo $feature->getUrl(); ?>"><?php echo $feature->getPageTitle(); ?></a></h3>
<p><?php echo $feature->getSubhead(); ?></p></td>
<?php endforeach; ?>
These methods are specific to Pages. Images might have a separate interface, and ditto for Articles, Posts, News, etc. I want to treat them all the same way, including the ability to sort featured items. Currently we have a field in our pages table that determines sort order, but obviously that wouldn't work if multiple types of content are being displayed.
Re: Featuring a variety of content in a CMS
Posted: Tue Jun 09, 2009 2:36 pm
by inghamn
In our CMS, I did the interface-stye thing. I made sure each of the things I was going to feature had the same getter functions available. I didn't bother writing an interface, though. Just made sure they all had getFeaturedTitle(), getFeaturedDescription(), etc. Those would be used when featured the object.
Re: Featuring a variety of content in a CMS
Posted: Tue Jun 09, 2009 4:54 pm
by allspiritseve
inghamn wrote:In our CMS, I did the interface-stye thing. I made sure each of the things I was going to feature had the same getter functions available. I didn't bother writing an interface, though. Just made sure they all had getFeaturedTitle(), getFeaturedDescription(), etc. Those would be used when featured the object.
Yeah, I can see how that'd work. I think I've talked myself into a separate object though.