Question

I am a newbie in Drupal, I just created a module and try to display. But the block HTML code breaks all boundaries of the Theme. How we can control the HTML in blocks ?

For example my block code is

function node_example_block($op='list',$delta=0){

    switch($op){
        case "list":
            $block[0]['info'] = t('THIS IS EXAMPLE NODE EXAMPLE ');
            return $block;
        case "view":    
            $block['subject'] = "THIS MY FIRST SAMPLE BLOCK";
            $block['content'] = get_tree_data();

            return $block;
    }
}

function get_tree_data(){

    /*
     $output = HTML CODES HERE .....
    */
     }

return $output;
}
Was it helpful?

Solution

I am not sure what you mean by "breaks all boundaries of the theme". If that means that your theme goes wrong when you use that block, then the answer is simply that your HTML is wrong - it may contain unclosed HTML tags for instance.

The only answer to that is to fix your HTML. You may want to use Drupal's HTML corrector to see if that is indeed the problem :

function get_tree_data() {
  /* fill $output */      
  return filter_filter('process', 3, -1, $output); /* Call htmlcorrector filter */
}

But I wouldn't recomend keeping it this way, as having a bug in your HTML could merely be a symptom of a bigger bug which you should fix.

OTHER TIPS

Do you have a tpl file for block ? If not then create a tpl file for a block like block-NAME.tpl.php and define HTML div tags according to your theme. Just check out default garland theme for block.tpl.php for reference.And i think its not a good idea to have html code in module, you can place this html structure in tpl file

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top