Quick informational for those unfamilair with everything leading up to this stage:

So for those of you delving into drupal, you will undoubtedly come to the point where you find the generic node layout extremely limiting. You've undboutedly found CCK at this point and are using it to create all these great fields that relate to the content, but now getting it all in order is important. As the node's content (with the generic node rendering) is rendered in the same order as it is filled out in the form, you may find that while you want the user experience to have them uploading pictures first, the pictures need to be below the body text, and not above it. Without advanced themeing, this can be a headache!
One solution people use is Panels. I'll address this quickly in saying that it works, but it's like strapping a soggy, mostly broken WWII rocket engine onto your honda so as you can drive up the street for lunch. It gets the job done but it's a whole mess of crap that generates awful code, is minimal in delivered functionality, and not nearly as dynamic as you can get with true themeing using the CCK variables. This of course doesn't even begin to touch down on how cumbersome it is in comparison to neat and clean templating files.
So why is this even important? Wekk your desired layout may be different for a blogpost with 12 pictures versus a blog post with one picture. Also one of the great headaches of a CMS is that you've given your clients a double edged sword. Sure they can add all the content they want, but if the decide suddenly not to add a picture, you're rather screwed. Also let's say you have a piece of content like "cars" for a car lot. They have current cars and then not current cars. You want each piece of content rendered differently, with one displaying MSRP, one displaying KBB. You also are tieing them into views, and for non-current vehicles you want to display all of the cars in a basic condensed version of the large format... yet not have to have the client re-enter the information for the car.
This is where being able to get your CCK variables out is important. This is where Content Template kicks ass and takes name. Install and enable the module like any other module, and it will appear under content. Go down to content templates, and click that. A nice list of all your different content types will be there, with an "edit template" list right beside it. Click that, and up pulls a screen just like the screen shot i have above. Now, there are two useful things here. One you have the current body template rendering, which aloen may help you out. If you simply want images below the body when rendered, but not in the node creation form (content creation) you can just take this, plug it into the appropriate node-contenttype.tpl.php, and you're done.
However, let's say you want to get real advanced. You want to have a different class depending on a choice the author made from a drop down list, such as "Option A, Option B, Option C, [or] Option D". Well now you can write a PHP if statement using that input. You simply click on "body variables" and down drops a list of ALL the variables in all of the arrays for the example piece of content it pulls from. Go down through there, find the appropriate variable for the field, and write your IF statement away.
Even more fun, let's say you're using imagecache. a program allowing users to upload one picture, and then automatically generate many other variations from it without having to resize it themselves. Image Cache is genius stuff when you're handing your webpage over to a mom and pop style business, and it's also nice for even experienced people as it is a major timesaver. Anyways, let's say you want your main image to be a full size image, but the rest you want to be the smaller image cache. What exactly do you do? Traditionally you'd have to create two image fields... which creates for a less than ideal user experience in my and others opinions. Using the foreach here, and a counter, you can generate the first image from a particular image caache, and the rest from another. You can also render a singular item in one container, and the rest in another.
Post new comment