embedded | Eric's Drupal Blog

Content tagged with: embedded

Eric's picture

Embedding a node in a collapsible fieldset

Here's a way you can embed a node in a collapsible fieldset into another page callback:

<?php
function MYMODULE_MYFUNCTION() {
 
$page_contents = "";
 
// ...code...
 
$fieldset = array(
   
'#type' => 'fieldset',
   
'#title' => t('MYTITLE'),
   
'#collapsible' => TRUE,
   
'#collapsed' => TRUE,
   
'#value' => node_view(node_load(MYNODEID), TRUE, FALSE, FALSE),
  );
 
$page_contents .= theme('fieldset', $fieldset);
 
// ...code...
 
return $page_contents;
}
?>

gradient spacer
Eric's picture

Embedding a view in a page or node layout

Here is how you can generate the html from a view and embed into a page callback or node.

<?php
function MYMODULE_MYFUNCTION() {
 
// ...code...
  // define view name
 
$viewName = 'MY_VIEW';

 
// get the view object
 
$view = views_get_view($viewName);
   
 
// create an array of arguments
  // NOTE: if you are using arguments, you can pass them into this function
 
$viewArgs = array();

 
// create view html
 
$viewHtml = views_build_view('block', $view, $viewArgs, FALSE, $view->nodes_per_block);
   
  if (
$viewHtml) {
   
$page_contents .= "<h3>" . $view->block_title . "</h3>";
   
$page_contents .= $viewHtml;
  }
 
// ...code...
}
?>

In this example, I am using a block view. You can also use a page or embedded layout and adjust as necessary. I find it helpful to show the contents of the view object to see what's available to you. For instance...

<?php
echo "<pre>" . print_r($view, TRUE) . "</pre>";
?>

gradient spacer
Eric's picture

Embedded CCK node form in collapsible fieldset

Here is how you can add a CCK node form in a collapsible fieldset into a page callback...

<?php
function MYMODULE_MYFUNCTION() {
 
$page_contents = "";
 
// ...code...
 
$page_contents .= theme('fieldset',
    array(
     
'#title' => 'MYTITLE',
     
'#collapsible' => TRUE,
     
'#collapsed' => TRUE,
     
'#value' => drupal_get_form('MYCCKNODETYPE_node_form', array(
       
'type'=>'MYCCKNODETYPE',
       
'uid' => $GLOBALS['user']->uid,
       
'name' => $GLOBALS['user']->name)
      )
    )
  );
 
// ...code...
 
return $page_contents;
}
?>

gradient spacer Syndicate content