I've been reading as much as I can about CCK today, but mostly seems to be around creating and themeing input forms and that's not what I want to do.

I'm looking to create a structured and styled page that outputs content I've already created.

Basically, what I'm looking to do is to restructure a bunch of highly structured pages that are handcoded in HTML and convert them over to CCK so I can standardized page structure across all simlar pages and simplify creation, editing and updating. The existing pages look like this: http://www.aboutcallingcards.com/speedypin-review.

I'd like the CCK version of teh page to look basically identical, including tooltips for 'labels' and simply plop the appropriate data value into the requisite fields.

If that makes any sense.

So far, what I have done is to create a custom content type called 'review'. I've defined several fields (basically the fields in the first table on sample page above). I've create a test node and populated these fields with data. That all seems fine. The page shows up, the data fields contain the correct info, etc.

But it doesn't look anything like the existing page - so it appears that what I need to do is something more ambitious with the themeing of the content to get it to look right. I think what I'm supposed to be doing is something akin to what's shown here http://drupal.org/node/101092 -- except this seems to be for forms and I don't see anywhere that describes how to simply output data you already have in the node.

But trying to follow the logic of the threa, I created a custom node template in my theme folder: node-review.tpl.php. I've added a custom class to that and know that that template is being picked up by the page when it renders.

But next step is to get the fields to print in the various slots in a tabular format. Can't figure out how to do that.

Appears I need to add something to template.php, but what? There are several versions on the thread of what to put into template.php and all seem to be designed for forms (vs. nodes - although I don't really know if this would change the code any). So I've added something like this to template.php:

// we register the form to the theme registry
function toaist_theme(){
  return array(
    'node_review' => array(
      'arguments' => array('node' => NULL),
      'template' => 'node-review',
    ),
  );
}

Then where I want the variables to print, I've added stuff like this to the node-review.tpl.php file:

<tr>
  <td class="lftbld1">Company URL</td>
  <td class="leftindent"><?php print $field_company_url; ?></td>
</tr>

where field_company_url is the name listed in the CCK manage fields table.

Actually, I've tried all sorts of combinations and variants along the lines of http://drupal.org/node/101092#comment-874839 -- meaning various combinations of things in template.php and node-review.tpl.php, but not getting it exactly right.

Can anyone get me a bit closer to the right answer here?

Thank you.

Comments

john.kenney’s picture

any ideas?

maozet’s picture

As the subject: install
1) http://drupal.org/project/devel
It is realy helpful, do everything with it

2) http://drupal.org/node/11816
3) print_r($node) in your node-review.tpl.php

john.kenney’s picture

thank you very much for the comments.

so i tried fiddling around with all the items you suggest and haven't made any particular progress.

#1. i installed devel module and played around with it, but I am not sure what i'm really supposed to do with it. i see the themer check box and can highlight stuff and see preprocess functions, but it is greek to me what those mean.

#2. what am i supposed to do with that list of variables? how do those fields relate to the custom fields i defined in CCK?

#3. this is helpful to print all that stuff out, but again it is a bit like reading greek. i see the variables there. they are printing on the page in the default CCK output (via print $content). but i can't tell if they are available to be printed otherwise. here is sample output from this:

[field_company_url] => Array ( [0] => Array ( [url] => http://www.ZheapCards.com [title] => [attributes] => Array ( [target] => _blank ) [display_url] => http://www.ZheapCards.com [display_title] => http://www.ZheapCards.com [label] => URL [view] => http://www.ZheapCards.com ) )

i think this is telling me that the variable is available to be printed on the page, yes?

if so, can you/someone tell me the correct php statement to print these variables?

on this thread (http://drupal.org/node/101092), there are at least 2 methods shown.

<?php print $field_company_url ?>

<?php drupal_render($form['review_field_company_url']); ?>

neither works. first one generates output of 'Array'. other generates output of empty field.

and i remain quite confused about the basic terminology. e.g., is any CCK thing a 'form' vs. a 'node'? what does the xxx_edit.tpl.php file do? is that required?

seems like it shouldn't be too tough, but perhaps the underlying mechanics are simply over my head.

maozet’s picture

#1) with devel module: click on your page part and expand the variables (on the bottom of the devel box). You will see a list of all variables available. This gives you lots of information of what is available to print out.

#3) try to add the following to your node-review.tpl.php

 print_r($node); 

. this gives your the structure of your node object. What ever you see there available for print.
try
print $field_company_url[0]->url; (for example)

john.kenney’s picture

Yay! I think we've got it. Thank you for your help.

To explain briefly what happened:

Using the variables list via print_r, I was able to print out other non-CCK variables using this format you suggested:

<?php print $path; ?>

Any of the basics.

But this would not work for any of the CCK variables. I tried all sorts of variants on what you suggested: print $field_company_url[0]->url; -- with the url, without it, with the [0], without it, etc. didn't work.

I then looked deeper into the print_r output and into the devel output and tried all manner of other variable names and print formats,... , but it was totally random and none of them worked.

Then having learned a bit more, I went back to look again at a module that I'd seen recommended in various threads - contemplate. I had installed it before, but couldn't understand it at all when i first looked at it. But it turns out to show the variables in exceptional detail in a way i could now understand having tried the other stuff. So this lead me to formats like this:

<?php print $field_company_type[0]['value']; ?>
<?php print $field_company_url[0]['view']; ?>
<?php print $field_review_company_name[0]['value']; ?>

which is sort of what you are trying to do with '->url', except using brackets.

these more complex formulations worked and now I appear able to put any CCK variable anywhere I want on the page.

So that's awesome and really helps me along. Thanks very much for pointing me in the right directions.

drewid’s picture

I was having the same issue and followed the suggestions in the thread but things were still not working for me. I could see the values using Devel and print_r, but something wasn't right.

The issue was that I had to remove the "$" in front of the field name and add "$node->" in front of the field name. For example:
This didn't work:
echo $field_page_template[0]['view'];
But this did:
echo $node->field_page_template[0]['view'];

Thanks John and thanks maozet for pointing us in the right direction. Now I'm psyched on Drupal once again!