Drupal: Pulling Dynamic Content in otherwise static pages
Presenting dynamic content into a static Drupal node is a real-life need that is not expressly catered for in pre-4.7x Drupal. The module 'flexiblock' attempts to do that, but it has never really worked for me because of the choices that I often make when it comes to themes and templates. My attempts to tweak my templates to be able pull blocks into other locations besides the traditional left and right columns have not been very successful with Flexiblock.
I have always thought that I could write an SQL query to SELECT content and use PHP to sort and present that cotnent within an otherwise static page (remember to select PHP Code as the input format). Challenged to present present information in multiple places (upcoming events), and being of the thought that it does nto make any sense to use a CMS and yet spend time hard-coding information in HTML around the website, I set out to find a solutions.
I do not claim to have invented anything. I am just writing this to draw focus to some good documents out there that each explain how to implement this in a variety of ways. This document is therefore an overview of those established methods.
Create a block and then call it into any section
As detailed by Boris Mann in his answer, once a block is created and published (remember to hide the block from other regions if you only want to use it within pages), it can be called in using simple PHP
print display_block(#blockid);
?>
Calling an existing variable
print event_block_upcoming($limit = 5);
?>
$block = module_invoke('block', 'block', 'view', 7);
print $block['content'];
?>
$sql = "SELECT node.title, node.nid FROM node WHERE type='flexinode-1' ORDER BY node.created DESC LIMIT 20" ;
$output .= "<ul>";
$result = db_query($sql);
while ($anode = db_fetch_object($result)) {
$output .= "<li>".l($anode->title, "node/$anode->nid")."</li>";
}
$output .= "</ul>";
print $output;
?>


