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

    <?php
    print
    display_block(#blockid);
    ?>
     
    This seems to be the shortest way to implement this. it should work because I have been able to pull in banners using the similar code. I tried this method but after reading that it has not been tested or documented elsewhere, I decided to look for another method.

    Calling an existing variable

    Instead of calling a block, I called the output variable that the event module uses to print the side-block by inserting event_block_upcoming($limit = 5); in the print argument of the above method resulting in:
     
    <?php
    print
    event_block_upcoming($limit = 5);
    ?>
     
    This will create a list of items already in an existing block (the number refers to the block ID) 
     
    <?php
    $block = module_invoke('block', 'block', 'view', 7);
    print $block['content'];
    ?>
     
    This will pull in a number of nodes from a specific node-type
    <?php
    $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;
    ?>
     
    This method works very well and the only challenge at this time is to integrate this into desired design (alternating row colours) of the artist's impression of the website. Since I have not seen a solution for that section, once I create it, I will post it here and refer to it from the Drupal website/forums
     
    The above-referenced document goes-on to detail many ways of pulling-in other kinds of content into page-nodes