php - Whats the correct way of outputting html in a custom module in Drupal -
i have worked on few project drupal, , main suggestion got when learning use views output data, although fine items found cumbersome achieve projects requirements in set time , style controls limiting.
i want know whats wrong doing this, or whats right doing this?
you run query specific data want.
function custom_block_get_item($nid){ $result = db_query("select `field_custom_item` {field_data_field_custom_item} entity_id = :entity_id", array( ':entity_id' => $nid, )); return $result; } then loop through creating html
function custom_block_display_blurb($nid){ $html='<div id="blurb_wrapper"><div id="recent_projects_blurb">'; $result=custom_block_get_blurb($nid); while($row1 = $result->fetchassoc()){ $a=check_markup($row1['field_custom_item'],'full_html','',''); $html.=' <span class="recent_project_text">'. $a.'</span>'; } $html.='</div></div>'; return $html; } finally display @ end
function custom_block_block_view($delta=''){ if (arg(0) == 'node' && is_numeric(arg(1))) $nodeid = arg(1); switch($delta) { case 'custom_block': $block['content'] = custom_block_display_blurb($nodeid); break; } return $block; } this seems kind of hacky way things, correct drupal way?
maybe mean using drupal theme layer? allows use of .tpl files , overriding. have simple block module here source here.
here documentation on using theme layer within module.
here official drupal docs on themeing (mainly themes rather using theme layer in module).
Comments
Post a Comment