Web "/>

EE1 plugin - remove duplicate html

13 October 2010 at 5:10 pm

I recently was hired to clean up a mess of a site done in EE1. I’ve moved most of my projects to EE2 by now, but this was a very fun task! The project was in such a dire state that I’ve never seen anything like it. Every template was strewn with hardcoded php and sql statements and not a single one of the many nice features in EE had been used. These guys had obviously never ever used EE but claimed to be experts. The company worked on the site for several months and eventually more or less gave up.

My first thought was that I had to make this more usable. The control panel looked like a mess so I decided to redo the whole thing from scratch. After 3 days of work, the client now has a site that is much simpler to use. All the features are the same, but 70+ templates have been reduced to ten, 20+ channels have been reduced to four, CSS reduced to half the size, all hardcoded parameters made dynamic and so on. Navigating the EE backend is much, much easier now.

As part of the job, I came across the need to remove duplicate output from EE. I was outputting a list of {categories} but since it was inside an entries loop I got lots of duplicate html. I could have solved this by doing some manual queries, but that may fail if EE is updated. Looping over a dataset of entries is more or less what EE was made for and just stripping off the duplicate code seemed like the most efficient solution.

I couldn’t find a smart way to do this, so I made a quick plugin that solved the problem. I just love how easy these things are with php and EE! The plugin is super easy to use and I’m posting it here so that others still using EE1 can use it.

The plugin works as a tag pair. Wrap it around any block of output to remove duplicate lines:

<br /> {exp:removeduplicatehtml}<br /> <img src=‘image1.jpg’ width=‘65’ height=‘30’ /><br /> <img src=‘image1.jpg’ width=‘65’ height=‘30’ /><br /> <img src=‘image2.jpg’ width=‘65’ height=‘30’ /><br /> <img src=‘image2.jpg’ width=‘65’ height=‘30’ /><br /> {/exp:removeduplicatehtml}<br />
This will produce an output like this:
<br /> <img src=‘image1.jpg’ width=‘65’ height=‘30’ /><br /> <img src=‘image2.jpg’ width=‘65’ height=‘30’ /><br />

Click here to download