Say I have a Content Type defined with 2 cck fields like so:
Content Type: CD_Title
cck Field 1: Artist_Name
cck Field 2: Artist_Url

I've created a View (using the Views Module) that lists the the Artist Name and CD title. Now I want to make the Artist Name a hyperlink to the URL defined in Artist_URL, the html equivalent of:

Artist_Name

Any clues on how to accomplish this?

Comments

ultimateboy’s picture

Sure. This can be done via theming. If you are using the phpTemplate theme engine, then you can simply create a tpl file node-[content-type].tpl.php (in this case: node-cd_title.tpl.php) inside of your current theme folder. Within this file, you can alter the output of the node.

You can then use <?php print_r($node) ?> to show you all possible fields to output. In this case, you probably want something like:

<a href="<?php print $field_artist_url ?>" title="<?php print $field_artist_name ?>"><?php print $field_artist_name ?></a>

The other solution for this particular case is to use the link module. This will allow you to do exactly what you want and also validates the information entered into the cck fields.

For more information about theming, be sure to see the documentation: Theme Guide.

Note: If you are planning on having the link point to a node on your site, it might be better to use something like node reference (or user reference if artists are users on your site).

--
-- matt tucker
    pingVision

-- matt tucker

eblues’s picture

thanks, Matt!

Since I'm currently php illiterate, I looked at the Link module first. It will do what I want with only minor limitations, which I can work around. So at least I know I can get it done now.

But I'm concerned about my growing dependency on add-on modules and reliance on their continued support as Drupal is revised, which I understand I can expect to happen every year or so. So I would like to avoid adding yet another module if I can.

I coincidentally started with the Chameleon theme because as a noob I wanted something simple, and customized that theme's default CSS to my liking (with much effort). This theme doesn't use tpl files. I'm not sure if that precludes me from using your suggestion of creating a custom tpl file to modify the output. But I was looking around in the Views admin, and I found the "Theme Info" link that shows a lot of options for adding tpl files as you describe through that module.

So it looks probable I can use the tpl approach, if not through the site theme then with Views. I'm gonna go away now and do some studying, and maybe even try to learn a little about php. It seems like php is the major key to making Drupal dance.

I greatly appreciate your suggestions. I searched Drupal.org and the Internet for several hours but just never hit on the right bit of info. You've given me one sure quick fix, and just enough to know where to start looking to possibly become more self-sufficient.

Herm

WorldFallz’s picture

But I'm concerned about my growing dependency on add-on modules, and reliance on their continued support as Drupal is revised...

This is a healthy concern, but I don't think you have to worry about it with this particular module. IMO there's basically two types of contrib modules-- building block modules and advanced feature modules. I consider most of the cck field modules to be of the building block variety-- like cck, views, nodequeue, panels, etc. You still need to look at the module's release history and issue queue activity, but I wouldn't worry about adding cck field modules in general. This particular one is well maintained, was among the early updaters for d6, and is maintained by an active member of the community.

just my $0.02 worth ymmv...

===
"Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime."
-- Lao Tzu
"God helps those who help themselves." -- Benjamin Franklin
"Search is your best friend." -- Worldfallz

eblues’s picture

This particular one is well maintained, was among the early updaters for d6, and is maintained by an active member of the community.

Thanks, that's reassuring to know.

WorldFallz’s picture

np... and hopefully this kind of module evaluation will be much easier after the d.o. redesign.

===
"Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime."
-- Lao Tzu
"God helps those who help themselves." -- Benjamin Franklin
"Search is your best friend." -- Worldfallz

eblues’s picture

Just thought I'd finally post a follow up here. As I mentioned, I was using a variation of the Chameleon theme, which does not use the phpTemplate theme engine. This limitation prevented me from using custom tpl files, and the Views2 defined theme tpl options as well.

However, after some investigation I noticed that themes that use the template engine have a template.php file rather than a *.theme file, so on a whim I tried changing the name of the Chameleon.theme file to template.php and added engine = phptemplate in the Chameleon.info file, and VIOLA, I now have a phptemplate driven theme.

This opened the doors to the Views2 tpl themeing options, and I was able to not only generate the URL linked Artist Names I first sought, I was also able to generate custom outputs for several fields in my views, greatly enhancing their functionality.

....Actually, thinking back on it now, perhaps I didn't even need to change name of the Chameleon.theme file. Adding the template engine to the Chameleon.info file may have been all that was needed to enable the Views2 tpl themeing options.

Either way, I'm one happy camper to have this functionality working. Thanks again Matt for your guidance. You gave me the necessary kick-start to get the themeing, access of node fields, and use of php figured out.

This custom stuff sure is not simple. It took me many days of trial and error to get the output I wanted. Even now, if I want to make a modification in this area, I have to go back and re-examine what I did before, before I can do it again.