Featuring a variety of content in a CMS
Moderator: General Moderators
- allspiritseve
- DevNet Resident
- Posts: 1174
- Joined: Thu Mar 06, 2008 8:23 am
- Location: Ann Arbor, MI (USA)
Featuring a variety of content in a CMS
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?
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
Re: Featuring a variety of content in a CMS
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?
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?
- allspiritseve
- DevNet Resident
- Posts: 1174
- Joined: Thu Mar 06, 2008 8:23 am
- Location: Ann Arbor, MI (USA)
Re: Featuring a variety of content in a CMS
More like the same view pull on a collection of different domain objects.PCSpectra wrote:it should be trivial to have two different views pull on the same model
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; ?>- inghamn
- Forum Contributor
- Posts: 174
- Joined: Mon Apr 16, 2007 10:33 am
- Location: Bloomington, IN, USA
Re: Featuring a variety of content in a CMS
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.
- allspiritseve
- DevNet Resident
- Posts: 1174
- Joined: Thu Mar 06, 2008 8:23 am
- Location: Ann Arbor, MI (USA)
Re: Featuring a variety of content in a CMS
Yeah, I can see how that'd work. I think I've talked myself into a separate object though.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.