Yes, all PHP code has to go in a snippet.
You can put HTML in the snippet if you need to. It just makes the site harder to maintain because you have to rewrite the snippet every time you want to change the output format.
The way to do it is to use an $output variable and add the HTML to it at various points in the code:
$output .= '<p>some HTML</p>';
Then put this at the end of the snippet:
The usual way to avoid that (and the "correct" MODx way) is to put all the HTML in a Tpl chunk with placeholder tags for all the values that the snippet will set. Then in your snippet, you can either set the placeholders with $modx->setPlaceholder(’placeholderName’, ’value’) or put the values into an associative array and send the array to $modx->getChunk():
$placeholders = array(
'placeholder1'=>'some value',
'placeholder2 => 'some other value',
);
With the first method, the snippet would end with:
return $modx->getChunk('TplChunkName');
With the second, it would be:
return $modx->getChunk('TplChunkName', $placeholders);
Hope that makes sense.