Create block programmatically based on node content In Views we can create a block that the content depends on the content of a node using contextual filters. So we can pass variables and check the visibility of the Views-Block.

Let’s say in our content type we have a field that has a text-field. In Views->Contextual->Our field->Provide default value-> content ID from URL can grab this.

But creating a block programmatically

hook_block_view($delta = '') {
…
$block['content'] = theme('item_list', array(
         'items' =&gt; ???,
          'type' =&gt; 'ul',
        ));
…
}


How we can grab these values form the node-field?

And if there are no values how we will hide the block?
Found a few modules depending on your need:

Node field block


  An easy way to create blocks with a collection of node fields. Focused on letting customers manage most of the content on a page in just one node. You can create multiple blocks for a node with one or a combination of fields and move them in different regions.


Field as block


  Field as Block provides an easy way to display one or more fields of the current node in a block.


There's a custom way also if you want. You can use below function for this purpose.

render(field_view_field('node', $node, 'field_myfield'));