drupal - Formatting HTML output of theme function -


i've implemented own theme function (theme_my_theme_function) , have implemented hook_theme tell drupal function. works correctly , output want on page, except...

when @ html source code, html code outputted function in 1 long line! how theme function output formatted html neat , easy read?

if want html formatted, you're going have when build html strings. easier way use template file opposed building strings of html manually (remember php html template language). there pretty write of how here: http://drupal.org/node/165706

the core node module has pretty example:

node.module:

<?php  /**  * implementation of hook_theme()  */ function node_theme() {   return array(     'node' => array(       'arguments' => array('node' => null, 'teaser' => false, 'page' => false),       'template' => 'node',     )   ); } 

node.tpl.php:

<div id="node-<?php print $node->nid; ?>" class="node<?php if ($sticky) { print ' sticky'; } ?><?php if (!$status) { print ' node-unpublished'; } ?> clear-block">  <?php print $picture ?>  <?php if (!$page): ?>   <h2><a href="<?php print $node_url ?>" title="<?php print $title ?>"><?php print $title ?></a></h2> <?php endif; ?>    <div class="meta">   <?php if ($submitted): ?>     <span class="submitted"><?php print $submitted ?></span>   <?php endif; ?>    <?php if ($terms): ?>     <div class="terms terms-inline"><?php print $terms ?></div>   <?php endif;?>   </div>    <div class="content">     <?php print $content ?>   </div>    <?php print $links; ?> </div> 

there may way integrate htmltidy drupal "beautifies" markup before it's output, i've never done myself.

ultimately, highly recommended not worrying formatting of html output. instead, use firebug firefox or inspector chrome/safari. these both have "inspect element" tool lets view markup of page in nice browsable, editable tree. it's invaluable web development.

*edit* theme_item_list minimal formatting of html output. here example of list generated theme_item_list:

<div class="item-list"><ul><li class="first">1</li>  <li>2</li>  <li>3</li>  <li class="last">4</li>  </ul></div> 

in code theme_item_list can see adds "\n" after <li>:

$output .= '<li' . drupal_attributes($attributes) . '>' . $data . "</li>\n"; 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -