Using a a plethora of plugins to make content management easier.
In this chapter of the Building an ExpressionEngine Site series, we will develop the right-column listing of “Latest Products”. This is a spot where using a couple plugins will help negate the need for additional content fields for site admins to enter and maintain.
OK - so way back in Chapter 2 of this series we created an embedded template for the right-column listing of “Latest Products”, and it’s just been sitting there with static placeholder content in it. Now that we have our Products section implemented all the necessary content is in place, we just need to re-coded that embedded template to now pull content from the “bees_products” weblog dynamically. Once it’s working, the product content will immediately appear on all of our content pages because all of them have that template embedded—definitely one of those moments where using a embedded templates will shine.
Template Requirements
So let’s take a look at what’s going on in that Latest Products section (view the site from Chapter 12). For each product there is a small thumbnail and a blurb of text. Well, cool - we have both of those already in the Products weblog as product_thumbnail and product_description fields.
Hold on though.
Our thumbnails are all currently 150px by 112px - quite a bit larger than the 59px x 54px thumbnails currently specified in the Latest Products code. And - our descriptions are quite a bit longer than we really want in this right-column space as well.
What to do?
One option would be to create two additional fields in the “bees_products” custom field group - one for a smaller thumbnail and another for a short description. Those fields could then be used in the Latest Products embedded template.
Workable, but that approach would increase the content required for each entry. You would also have to train a content admin to know what fields show where on the site, and rely on them to create the thumbnails in each size correctly. Overall - not an elegant solution - especially when the necessary content is already in ExpressionEngine, just not quite formatted to our liking.
The second option?
Plugins to the Rescue
Yes - it’s a good spot to use some plugins to extend the functionality of “out of the box” ExpressionEngine. If you haven’t yet browsed the EE Plugin Library now is a good time to do so. For our purposes today we’ll need two plugins from the library:
We’ll also be using a relatively new plugin that I noted recently in the EE forums - the Image Resizer published by user Lumis (Lumis I’ll gladly credit you by proper name if you want...).
Installing Plugins using the Plugin Manager
There are two basic ways to install plugins - using the Plugin Manager, and not using the Plugin Manager.
Since the first two plugs we need are available in the EE library, you should be able to install them via the manager. Note: This assumes you have entered your EE license number in the Control Panel under: CP Home > Admin > System Preferences > General Configuration. If the license has not been entered, the list of available plugins will not appear when you browse to the Plugin Manager at CP Home > Admin > Utilities > Plugin Manager will not appear in the right column. To proceed you can either enter your license number, or install all three plugins via the second method using FTP.
OK - if the Plugin Manager shows (and neither the HTML Strip or Word Limit plugin is already installed), simply browse the list of available plugins until you find both of these and click the “Install” link. The plugin should install and then appear under the left-column list of installed plugins.
Installing Plugins without the Plugin Manager
Regardless of how you installed the first two plugins, you’ll need to install the Image Resizer plugin using the approach because it’s not—as of this writing - offered via the EE plugin library. To install this plugin:
Using Plugins
OK, now what?
By installing plugins, you now have some additional tags you can use in your templates. You can usually get details of the plugins-specific tags and parameters by clicking it’s title in the Plugin Manager page. I’ll let you explore the different parameters of these specific plugins on your own, and just show you how I’ve used them here.
Working up the Template
OK - we could just jump to the finished product, but let’s take this in steps so can see the logic of using the plugins.
First-up - the template with no plugins, using our existing content.
Here’s the code - the weblog:entries tag will stay the same through all of these examples and is pretty straightforward. Limiting to 3 will get us the last 3 products entered, all unnecessary data is disabled for performance, and the dynamic="off" will ensure the last 3 products will appear no matter what page this code is rendered on.
<h3>Latest Products</h3>
<div class="lcontent">
{exp:weblog:entries weblog="bees_products" limit="3" disable="categories|pagination|trackbacks|member_data" dynamic="off"}
<p>
<a href="{url_title_path=building_series/chapter_13_product_detail}"><img src="{product_thumbnail}"/></a>
<strong>{title}: </strong>{product_description}
<a href="{url_title_path=building_series/chapter_13_product_detail}">more >></a>
</p>
{/exp:weblog:entries}
</div>
And here’s the result. It’s usable, but not as nice as the original template styling:
OK - let’s tackle that thumbnail size first. Here’s the code modified to use the image sizer plugin. You can see I’ve specified a fixed height of 54px, and the plugin will resize the image to the correct width dynamically:
<h3>Latest Products</h3>
<div class="lcontent">
{exp:weblog:entries weblog="bees_products" limit="3" disable="categories|pagination|trackbacks|member_data" dynamic="off"}
<p>
<a href="{url_title_path=building_series/chapter_13_product_detail}">{exp:imgsizer:size src="{product_thumbnail}" height="54" alt="{title}"}</a>
<strong>{title}: </strong>{product_description}
<a href="{url_title_path=building_series/chapter_13_product_detail}">more >></a>
</p>
{/exp:weblog:entries}
</div>
And here’s the result. Our images look better, but our text spacing is still off:
If you do a view/source and look at the rendered code, you’ll see that our main culprit is paragraph tags. The product_description field is set to be formatted as XHTML - so that returns one set of P tags. The template is also providing P tags - wanting to wrap each product’s image and text in one paragraph. So let’s use the HTML Strip plug-in to remove the P tags from the product description field for round three:
<h3>Latest Products</h3>
<div class="lcontent">
{exp:weblog:entries weblog="bees_products" limit="3" disable="categories|pagination|trackbacks|member_data" dynamic="off"}
<p>
<a href="{url_title_path=building_series/chapter_13_product_detail}">{exp:imgsizer:size src="{product_thumbnail}" height="54" alt="{title}"}</a>
<strong>{title}: </strong>{exp:html_strip}{product_description}{/exp:html_strip}
<a href="{url_title_path=building_series/chapter_13_product_detail}">more >></a>
</p>
{/exp:weblog:entries}
</div>
Much better - no nested P tags coming out now. But - some of those descriptions are long for that space. Let’s use the the word_limit plugin to truncate those down. Here’s the new code - note that you can nest plugins for the desired results:
<h3>Latest Products</h3>
<div class="lcontent">
{exp:weblog:entries weblog="bees_products" limit="3" disable="categories|pagination|trackbacks|member_data" dynamic="off"}
<p>
<a href="{url_title_path=building_series/chapter_13_product_detail}">{exp:imgsizer:size src="{product_thumbnail}" height="54" alt="{title}"}</a>
<strong>{title}: </strong>{exp:word_limit total="15"}{exp:html_strip}{product_description}{/exp:html_strip}{/exp:word_limit}
<a href="{url_title_path=building_series/chapter_13_product_detail}">more >></a>
</p>
{/exp:weblog:entries}
</div>
And the result? Here’s the rendered site: Chapter 13 Site. Correct thumbails, one paragraph per product, and truncated descriptions all without addtional content fields to maintain. All within an embedded template so any changes are instantly reflected across your entire site. Definitely cool.
Just for good measure, here is the text version of the final latest products embedded template: chapter_13_latest_products.txt.
Next up? Starting the Services section.
Visit Train-ee.com for the latest in ExpressionEngine training designed with one goal in mind - to get you up to speed on ExpressionEngine® as quickly as possible.
The latest Train-ee Products:
The latest from the Train-ee blog:
November 14, 2007
Taste-ay, some good reasons to use a few specific plugins.
I’m way behind in following along with the bEEs series(just noticed the acronym, love that too). The alternate template I’m working on, just by chance has a nice spot to add the new products. A div called thirds that is at the bottom of the main content area, not in the sidebar.
These plugin’s will make that tick too, keeping them at a similar height will be best since they are side by side.
Do you have a list of plugins you most commonly use then?
Thanks again Michael.
November 14, 2007
No - not really. What I do try and do is review the list every couple of weeks just to try and remember what’s out there so I don’t spend hours coding something that a plug-in would accomplish in minutes.
November 14, 2007
following on from my misplaced query in Chapter 9, I’d forgotten to upload the image resizer plugin, (in too much of a rush to see results). Anyway, I did that, and now get the page rendering again, but no images. It doesn’t seem to have placed a resized image in the cache
November 23, 2007
mmmm… excellent tutorial all the way—thank you! But when I’ve tested the plugin Image Resizer it doesn’t work… Do you use any sort of plugin like ‘Extract Url’ or something to exctract the url to the image? See following thread http://expressionengine.com/forums/viewthread/62138/P54/#321620
Greetings from a very cold Sweden :-(
/Henrik Eklund
November 23, 2007
Hi Henrik -
No - I’m not using any plugins not discussed in the article.
Make sure though - that when you’re uploading your images you are choosing “URL Only” when inserting the code.
And - that in your weblog preferences you have EE configured to not automatically turn urls into links.
November 23, 2007
ahh, you’re a star
Although it worked out fine with “Embedded in entry” selected too. I think he has updated the plugin to support this “Embedded in entry"-thing…
November 27, 2007
Mike,
Thanks to you, my love for EE, and my bright green, super-cool test site is growing as well.
Can’t wait for Chapter 14!
December 09, 2007
I’m having a problem again. I can see the product images before adding the image resizer code but not afterward. I created the writable cache folder and made sure URLs aren’t automatically made links. The plugin shows up on in the admin panel. Does it work with EE Core?
December 10, 2007
It should. If you are using my code exactly then I’d suggest a post in the EE forums for the author of the plug-in.
December 28, 2007
Hey Mike, I found the problem. I’m developing on Mac OS X 10.5 and GD for php5 isn’t configured. I found some resources to fix it. Thanks again!
December 28, 2007
Ah. Good catch. Thanks for logging it here.
January 15, 2008
FYI: The Building an ExpressionEngine Site series is now available for purchase as an eBook on the newly-launched Train-ee.com.
February 28, 2008
Hey Mike, I’m also not seeing any images after using the image sizer plugin. I have the GD library installed (finally) and verified it is enabled, have created a writable “cache” directory in my /images/interface/building_series/ folder. Also made sure I have checked yes to the option to category URL Title under Global Weblog preferences.
Not sure what else I need to do to get this to work. Do you have a solution to this in your book? I’ll be more than happy to buy if that’s the case. Please help!
February 28, 2008
Hi Carlos, hey I dug up a link for the GD library, if it helps:
http://www.libgd.org/Support
And there’s always the:
http://expressionengine.com/forums/
Michael’s down in sunny Austin, TX for a few weeks.
He could pop in sometime here, just trying to help.
February 28, 2008
@Carlos:
I just responded to your email, but I’m using GD2 in my image resizing prefs...(CP Home › Admin › System Preferences › Image Resizing Preferences). I hope that helps!
February 28, 2008
Thanks Ty. I looked there but there is no documentation for Leopard only Tiger. Do you know of a way to make sure that the GD library is actually working? I looked into my phpinfo() file and it looks like it is enabled:
gd
GD Support enabled
GD Version bundled (2.0.34 compatible)
FreeType Support enabled
FreeType Linkage with freetype
FreeType Version 2.3.5
GIF Read Support enabled
GIF Create Support enabled
JPG Support enabled
PNG Support enabled
WBMP Support enabled
XBM Support enabled
Maybe i have the cahce folder in the wrong place??
February 28, 2008
@ Leroy
Thanks, Leroy. I also had GD2 in my preferences and it still doesn’t work. Even tried switching it to just GD but it did nothing.
This is so frustrating, I want to ring GD’s neck!
February 28, 2008
Hey Carlos -
Checking in from a DQ in East Texas...
The book doesn’t really go into any greater detail about the server-side requirements for the resizer plug-in.
Honestly—if getting it to work is that much of an issue I’d either contact the author of the plug-in, re-work the site design to use the same size thumbnails everywhere, or add another custom field for the smaller thumbnail.
February 28, 2008
...and this is really Mike...forgot to sign out my wife again…
February 28, 2008
Thanks Mike. I just created another custom field and that did it. Much appreciated it.
February 28, 2008
Hey Mike, I bought your book dude. Almost done with this tutorial but just wanted to show my appreciation for what I got out of it.
keep up the good work.
May 14, 2008
Hi Mike,
i know you’ve had a lot of Resizer questions but sorry heres another!
before i used it everything looked correct, when i put in the extra code appears the image disappears & source code is empty there.
(my host has just verified i’ve GD2 enabled on my server, i’ve created a writable cache folder, made sure URLs aren’t automatically made links… )
Looking back it seems you uploaded your product images thru Publish on EE whereas I uploaded them via FTP.
Would this be an issue?
cant figure out what else cud be…
thanks a mil!
May 14, 2008
Veronica:
If you’re feeding the plugin a valid path to an image it shouldn’t matter - but again you really should be contacting the plugin author (or posting in the EE forums) for additional help with it.