0

I am trying to create a custom content pane where I would be able to specify 8 values and create 4 divs with 2 values in each one of them. For this I am extending cTools module by creating a plugin. I am already able to fetch input and store it in $conf variable. The problem is that it seems that everything I do in render function doesn't work. At first I though I had some naming problems. My module name is

uzduotis

And here is my code for render function:

function uzduotis_render($subtype, $conf, $args, $context) {


  $block = new stdClass();
  $block->title = "4Divs";

  $html = '';
  foreach ($conf as $key => $items) {
       $html .= '<div class="element">' . $items['text'] . $items['link'] . '</div>';   
  }

  $block->content=$html;

  return $block;

  dpm($block);
}

I try to dpm my block and I get nothing, also another strange thing is that even a block title doesn't show up which I guess notifies that something is completely wrong. Can someone please point out what is wrong? If you need some additional information, please ask for it and I will update. Thank you in advance.

  • So are you trying to leverage the Drupal Blocks system, or are you just using the variable $blocks as a personal preference? – Remog Sep 25 '16 at 17:47
0

Blocks need to be render array. You are returning an object. This is how to do it:

function uzduotis_render($subtype, $conf, $args, $context) {
  $block = array(
    'title' => '4Divs',
    'content' => array(),
  );

  foreach ($conf as $key => $items) {
    $block['content'][] = array(
      '#prefix' => '<div class="element">',
      '#suffix' => '</div>',
      '#markup' => $items['text'] . $items['link'],
    );
  }

   return $block;
}
  • Thank you, but I still can't solve this problem. In my $conf variable I have values named like this: text1, link1, text2, link2 ... text4, link4. Every number after variable name is indicating in which div element it will be stored. But on the markup I only have text and link and I am not sure how to add these into it. – Viktor Sep 26 '16 at 6:40
  • I don't really understand the problem from your question, but it's different from the original question, so you should start a new thread/question on the matter. – Jaypan Sep 26 '16 at 7:08
  • I did what you said and you can find my new topic Here – Viktor Sep 26 '16 at 7:22
1

You cannot run any code after a return statement. By definition the return will exit the function. Try moving the dpm call to just before the return statement.

As an aside, I believe that best practices say that $block->content should be a render array and not straight up html...

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.