0

I am building a custom block in a module, like this:

<?php

function filterblock_block_info() {
  // Sökfilter till temperaturöversikten.
  $blocks = array();

  $blocks['filterblock-temperatur'] = array(
    'info' => t('Temperatursökfilter'),
  );

  return $blocks;
}

function filterblock_block_view($delta = '') {
  $block = array();
  switch ($delta) {
    case 'filterblock-temperatur':
      $block['subject'] = t('');
      $block['content'] = filterblock_block_content();
      break;
  }
  return $block;
}

function filterblock_block_content(){
    return drupal_get_form('temperaturfilter');
}

function temperaturfilter($form, &$form_state)
{
    $form = array();

    $form['alla'] = array(
        '#type'         => 'textfield',
        '#title'        => t("Alla"),
        '#weight'       => 10,
        '#required'     => false,
    );
    $form['IR'] = array(
        '#type'         => 'textfield',
        '#title'        => t("IR"),
        '#weight'       => 11,
        '#required'     => false,
    );

    $form['hightemp'] = array(
        '#type'         => 'textfield',
        '#title'        => t("> +500 °C"),
        '#weight'       => 12,
        '#required'     => false,
    );
    $form['lowtemp'] = array(
        '#type'         => 'textfield',
        '#title'        => t("< -50 °C"),
        '#weight'       => 13,
        '#required'     => false,
    );

    return $form;
}

In my template file I have this:

   <?php $block = module_invoke('filterblock', 'block_view', 'filterblock-temperatur'); ?>
   <?php  if ($block['content']) {
     $output = "<div class=\"filter-block\">\n";
     $output .= "<div class=\"content\">".$block['content']."</div>\n";
     $output .= "</div>\n";
     print $output;

But the only thing that is rendered on the page is the word "array". I have checked with var_dump in the block module that $block['content'] actually contains the fields from the function temperaturfilter. I have tried to use print render($output) in stead of just print, but with no luck.

What am I doing wrong?

1

You haven’t rendered the render array:

$output .= "<div class=\"content\">".render($block['content'])."</div>\n";
  • Thank's a lot! You saved me a lot of time. That worked straight away. – TBJ Jan 28 at 13:07

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.