home resources search newsjoinmembers: 6961
PHP Flash Java Ruby Windows Linux
Hiveminds | Fri, 2007-04-06 07:40  tags: ,

While implemeting a network of Drupal sites we have run into a problem it is one that is solved in a the SmileTag Chat module but now we need something on a larger scale. The problem is using Drupals forms API or any internal forms and HTML does not have a templating system. So designers are forced to manipulating module code to produce layouts.

Hopefully it will keep us from having to make a template system per module (file_get_contents is what we are using now). The follwing method implemented is simple enough from a designers point of view as it is a nice standard way of doing things.

Solution: catch the theme, but pass it on to phptemplate to render

<?php

function flashgame_page() {
    
$form['title_f'] = array(
  
'#type' => 'textfield',
  
'#title' => t('Subject'),
  
'#default_value' => 'titlenothing',
  
'#required' => TRUE,
  
'#weight' => -5);
  
$form['body_f'] = array(
    
'#type' => 'textarea',
    
'#title' => t('Body'),
    
'#default_value' => 'bodynothing',
    
'#rows' => 20,
    
'#required' => TRUE);
    
$output drupal_get_form('flashgame_page',$form);
  return 
$output;
}
function 
theme_flashgame_page($form) {
  
$output 'start form theme in module->';
    
$output .= form_render($form['body_f']);
  
$output .= form_render($form['title_f']);
  
$output .= '<div class="foo">';
  
$output .= '<div class="bar">';
  
$output .= '</div></div>';
  
$output .= form_render($form);
  return 
$output.'<- end form theme in module';
}
?>

template.php

<?php

/**
* Catch the theme_item_list function, and redirect through the template api
*/
function phptemplate_flashgame_page($items = array(), $title NULL) {
  
// Pass to phptemplate, including translating the parameters to an associative array.
  // The element names are the names that the variables
  // will be assigned within your template.
  
return _phptemplate_callback('flashgame_page', array('form' => $items));
}
?>

flashgame_page.tpl.php

<?php

    $output 
.= 'start templated form theme';
    
$output .= form_render($form['body_f']);
    
$output .= '<div style="background:red"> Stop you have to fill in this page!!!</div>';
  
$output .= form_render($form['title_f']);
  
$output .= form_render($form).'';
  print 
$output.'<- end templated form theme';
?>

http://drupal.org/node/127643

printer-friendly version

Hiveminds's picture
This article brought to you by the Hiveminds Magazine - Staff. Contact us if you want to post an article or announcement anonymously
Thoughtbox - So what did you think?



 
 
Drupal Joomla! Drupal Wordpress Content Management Systems Adobe Flex ASP.NET
 videos
 articles
 blogs
 comments
 downloads
sitemap

Newsletter

Get updates on Hiveminds services, articles and downloads by signing up for the newsletter.

Editor's choice

Some of the better articles, stories and tutorials found at Hiveminds.

Find more

Find more of Hiveminds articles, stories, tutorials and user comments by searching.




Picked links

Hand picked websites and articles from around the web that provide quality reading.

page top