Custom module blocks: where to put html code? I have a custom module that implements hook_block_view. I would like to know where should I put extensive html code for a block content.

For example:

$block['title'] = t('TEST');
$block['content'] = '&lt;div id="user-custom-block"&gt;';
$block['content'] .= ... 50 LINES OF HTML.
$block['content'] .= '&lt;/div&gt;';


What I did so far was to create a .tpl.php file and put all this code there, and then only call:

$block['title'] = t('TEST');
$block['content'] = theme('user_custom_block');


Is it correct?

If yes, so far, so good. But what if I have a "complex" logic inside of this block content? 

For example:

$block['title'] = t('TEST');
for...
  $block['content'] = '&lt;div id="user-custom-block"&gt;';
  if:
    $block['content'] .= ... 50 LINES OF HTML.
  endif;
  $block['content'] .= '&lt;/div&gt;';
endfor;
etc
etc


Is this still ok to use in a .tpl.php file? If not, which approach should I use?

Should I use something like this?

/**
 * Implementation of hook_block_view().
 */
function custom_block_view($delta='') {
  $block = array();
  switch ($delta) {
    case 'my-block-id':
      $block['subject'] = t('Block Name');
      $block['content'] = custom_contents();
      break;
  }
  return $block;
}

/**
 * custom html block
 * @return string
 */
function custom_contents() {
  return '
      &lt;/p&gt;&lt;div class="body"&gt;
        Hello World, this is a example custom Block
      &lt;/div&gt;&lt;p&gt;
    ';
}
You could improve that with 2 different options:
1) Creating a theme function
2) Creating a template file (tpl)

The tpl may be a cleaner option, but they are both similar. In both cases, you should pass preprocessed variables instead of putting the logic inside the theme function/tpl file.

Also, note that the literal strings should go through the t() function.