cck

Hide my block view if CCK field is empty

Published September 21, 2010

Let's say you have a CCK Imagefield you'd like displayed in a sidebar instead of the main $content area of your page. You can check exclude under Display Fields for that content type, and then use Views to pull out the field and stick in a block display, but if your node does not contain an image, you may notice that a few empty <div> tags are returned, and your theme might not be too friendly in this case. Now you need to find some way to hide that view if the field is empty...

Why not try adding a filter to the View?

Manual Control of ImageCache Cropping with Imagecache Javascript Crop Module

Published March 9, 2010

While Imagecache is a stellar tool to automatically create and display resized and cropped images on your site, sometimes a bit more control is necessary.

Imagecache cropping is an automatic process that crops from the center of your image. So, if the most interesting part of your image is in the upper-left, it will most likely be cut off at least partially in the resulting image.

Setting Default Year in CCK Field

Published September 18, 2009

If you use CCK often, then you've probably at least once had to implement a select box where the user can select a year value. Sometimes they're used for birthdays, magazine issues, events, or even historical reasons.

You can easily populate the "Allowed values" textarea of the field's "edit" page, but how can you quickly set the default value to the current year (and not have to worry about changing it every year)?

Adding photos to an event page with Views Attach

Published August 27, 2009

There are often 17 ways to do any particular action with Drupal - here is #18 on the list of "How do I display related content on this node's page?" You'll be using the Views Attach module and a nodereference field.

In this example, you want to relate a photo to an event. Inside the photo's content type, create a nodereference field that is able to reference the event content type. When a user is adding a new photo, she will be able to choose the related event if applicable.

Theming Nodereference - or - Reusing Complex Data in Drupal

Published August 1, 2009

This is your moment, you've decided to step up and make a job board for your local Drupal User Group. You spend some time thinking about everything you'll need, including the job listings themselves. You'll want to gather the standard info, like job title and job description, salary, experience, the works. When it comes to gathering company info, your instincts make you take a few extra moments to plan. If you think about this from the perspective of the person posting 6 or 7 jobs, she would end up having to type (or at least copy and paste) the business' contact information each time. If you think about collecting 3 or 4 fields for each business, then that's about 20 extra form fields for the user to fill out. If she then decides to change the info, let's say she made a typo, she now must click through each edit screen 6 or 7 times. That amounts to hundreds of clicks and several hundred repeated keystrokes. There must be a better way. A nodereference can help your users. Once finished, you will have two nodes, one for a job and another for a company, and yet you will still display the information about the company inside the job listing. By the end of this tutorial, you should understand what a nodereference is for, how to create and use one, and finally, how to use template files to theme the output of the nodereference and get the most out of the relationship.

Create Referenced Nodes On-The-Fly

Published July 21, 2009

If you use CCK's Node Reference field often, then this tip is for you.

Occasionally I run into the situation when I start adding a new node that contains a Node Reference field only to get half-way through before realizing that the node I want to reference doesn't exist yet. At that point I have to stop what I'm doing, open a new browser window, create the node I want to reference, then reload the original node's "add" form. What a hassle.