4

When a CCK field is added, we get the rendered output in the node page as $<field_name>_rendered.
How can we get a variable in the same way when we alter the form and add new field?

  • if i have created some extra fields using form alter in a content type and using node api i have saved them in a table i have created in database. if i need to get the output in the node page, i know that i have to use function wsf_action_nodeapi(&$node, $op) { if ($node->type == 'action') { switch ($op) { case 'view': $node->content['my_field_name']="The content retrived form database"; break; ... } } } my question is when i use the cck to create a field in the content type, i can access the data in the node page as $my_field_name_rendered. – Satya Jun 6 '11 at 3:45
  • my question is when i use the cck to create a field in the content type, i can access the data in the node page as $my_field_name_rendered. how can i load the value into $my_field_name_rendered when the node is rendered. – Satya Jun 6 '11 at 3:46
  • So you're altering the form to add a new CCK there ? Why don't you add the field in your Content Type and alter the form to make it disappear when you don't need it ? This way the rendering process will work as usual. – tostinni Jun 9 '11 at 20:42
  • Tostinni.. i am adding a new field not a cck. – Satya Jun 10 '11 at 17:03
  • Do you have some code to enlighten us a little because it's quite difficult to understand what you're doing and what result you expect. – tostinni Jun 10 '11 at 17:07
2

To load the data back to the node and render them, you first need to implement a hook_nodeapi load. Here some a short example:

function satya_module_nodeapi(&$node, $op, $teaser, $page) {
  switch ($op) {
    case 'load':
      // retrieve the p1 value from custom_table (it's better to use vid instead of nid to allow revisions.
      $p1 = db_result(db_query('SELECT p1 FROM {custom_table} WHERE vid = %d', $node->vid));
      return array('p1' => $p1);
      break;
  }
}

Then you will have a $p1 variable available in your node.tpl.php.

If you don't know yet the Examples modules, I'll definitely recommends it to have great examples and developer documentation for a lot of hooks.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.