0

So I am trying to create a block to list the cities of the scrapyards in the system and i've followed some tutorial and i'm not even getting the block to show up in the list.

I have dir created at: /sites/all/modules/list_city and inside that I have the necessary .info and .module files.

The info file contains this:

name = List City Module
description = List the scrapyard cities
core = 7.x

And the module file contains this:

<?php
/**
 * Declare what blocks are provided by this module.
 * Implements hook_block_info().
 */
function list_city_block_info(){
  $blocks = array();
    $blocks['list_city'] = array(
      'info' => t('My Custom Block'),
  );
  return $blocks;
}

/**
 * Define what our block is going to look like.
 * Implements hook_block_view().
 */
function list_city_block_view($block_key){
  $block = array();
    if($block_key == 'list_city'){
      $block['subject'] = t('Marty McFly Countdown');
      $block['content'] = t('Marty will arrive in ').(strtotime("2015-10-21")-time()).t(' seconds.');
    }
  return $block;
}
?>

I'm not sure what I am doing wrong. The tutorial says it should show up in the lost of blocks but i'm not seeing it.

Also how could I go on to just list field_city of the scrapyard node.

Linking me to some page won't help much because at the minute i've looked at 10+ websites with tutorials on how to create blocks and i'm having no luck at all

EDIT: I've looked at a simpler tutorial and i'm now trying to use this updated code

  • 1
    Try to clear cache. – Potney Switters Nov 13 '14 at 14:12
  • Yea i've been going to performance and clicking the clear all cache button on every attempt – Callum Nov 13 '14 at 14:13
  • You have info and configure, but where is hook_block_view?! – Mołot Nov 13 '14 at 14:15
  • 1
    Btw for examples check:drupal.org/project/examples – Potney Switters Nov 13 '14 at 14:17
  • 2
    Maybe a silly question but did you enable the module? – Akko Nov 13 '14 at 14:40
2

The following worked for me:

listcity.info

name = List City Module
description = List the scrapyard cities
core = 7.x

listcity.module

/**
* Implements hook_block_info().
*/
function listcity_block_info() {
  $blocks['listcity'] = array(
    'info' => t('List City'),
  );
return $blocks;
}

Make sure that you enable the module. (I've forgotten to do this before)

In your code sample there is a closing php tag ?> This shouldn't be in the module file.

  • Your just trying to get some free easy rep – Callum Nov 13 '14 at 14:44
  • If I could comment on your question I would. Really, I am just trying to help. – SpartyDan Nov 13 '14 at 14:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.