This is driving me crazy. I get so close to being done, and then I realize that I'm not.
I having this huge debate with myself over the way to handle a particular (very important and central) feature. But arguing with myself isn't very productive. I need a nerd, stat.
Here's the shortened version of the problem. There are 14,000,000 ways to do anything, I want the best one. At this point in the system, a user has requested to view an object. It doesn't really matter what but, for fun, we'll say it's a page in an image gallery with all the thumbnails of the pictures on it. I've narrowed it down to two ways of doing it.
The first method would put most of the work in the gallery handling code. This means that it's written in PHP and isn't really meant to be edited by everyday users. In this case, the gallery code would access a configuration variable to determine how many thumbnails to show on a page. Then it would access a parameter passed to it to determine which page the user was requesting. Then it would get the images that were requested and prepare them to be displayed. Then it would pass all of this information on to a template. The template (which should be easily editible by those who know a little HTML) would then cycle through the images and display them. The template would handle deciding when to start a new row and, therefore, must have some notion of how many thumbnails have been requested for each page, although it doesn't have to… it just means that all of the pages might ALWAYS not have enough images to fill the last row in the display. This is a nice option because the code in the template is kept to a minimum.
The second method is much more flexible, however it puts a lot more code in the template. Instead of using a configuration variable to determine how many items are on a page, the template actually requests the number of items that it would like. This is faster because the data doesn't have to be preprepared. It's also more flexible because the template is the source for important information like the number of thumbnails on a page. If the website owner should choose to change how a page looks, she wont have to update the template and the configuration. Just the template will do. However, the code looks MUCH more complex.
Allow me to give you an example of each version of the code.
Simple Template:
<html> <head> <title> Gallery </title> </head> <body> <p> <a href="{$selfurl}/{math equation="x - 1" x=$page}"> PREVIOUS PAGE </a> | <a href="{$selfurl}/{math equation="x + 1" x=$page}"> NEXT PAGE </a> </p> <table> {section name=thumbnail loop=$thumbnails} {if $smarty.section.thumbnail.index mod 3 eq 0} <tr> {/if} <td> <p> <a href="{$thumbnails[thumbnail].url}"> <img src="{$thumbnails[thumbnail].imgsrc}" /> </a> </p> <p> {$thumbnails[thumbnail].description} </p> </td> {if $smarty.section.thumbnail.index_next mod 3 eq 0} </tr> {/if} {/section </table> </body></html>
Complex Template:
<html> <head> <title> Gallery </title> </head> <body> <p> <a href="{$selfurl}/{math equation="x - 1" x=$pageparams.page}"> PREVIOUS PAGE </a> | <a href="{$selfurl}/{math equation="x + 1" x=$pageparams.page}"> NEXT PAGE </a> </p> <table> {getchildren type="image" num="9" start="$pageparams.page * 9" assign="thumbnails"} {section name=thumbnail loop=$thumbnails} {if $smarty.section.thumbnail.index mod 3 eq 0} <tr> {/if} <td> <p> <a href="{$thumbnails[thumbnail].url}"> <img src="{$thumbnails[thumbnail].imgsrc}" /> </a> </p> <p> {$thumbnails[thumbnail].description} </p> </td> {if $smarty.section.thumbnail.index_next mod 3 eq 0} </tr> {/if} {/section </table> </body></html>
In case it's hard to tell the difference, look at the "getchildren" command being issued in the second template. That's the biggest change between the two. The nice thing about the second version is it gives the template author so much more power. So many other cool things can be done if the templates work in this fashion. However, this means that the template author must know that he is looking for children of this node that are of type "image". Without this knowledge, her template wouldn't display any thumbnails at all.
Or maybe there's a better way. Tell me how YOU would propose the template should look to allow a user to display any number of thumbnails on a page. Anything. Please. I'll entertain any and all suggestions.











