0

I am trying to print out multiple variables in a block content, but drupal returns:

Parse error: syntax error, unexpected '$search_field' (T_VARIABLE) in C:\seu\xampp\htdocs\iptp\sites\all\modules\custom\lasearch\lasearch.module on line 70

Here is my Code:

/**
 * Implements hook_block_view
 * 
 * This creates a block which shows the search results
 * 
 * @param type $delta
 * @return type
 */
function lala_search_block_view($delta = '') {
    $block = array();

    switch ($delta) {
        case 'lala_SEARCH_RESULT':

            $block['content'] = array(
                '#markup' => _lala_search_search_page(),
            );
            return $block;
            break;
    }
    switch ($delta) {
        case 'lala_lanavigator':
        $search_field = module_invoke('search', 'block_view', 'search');
        $search_text = _lala_search_get_laavigator('prefix');
            $block['title'] = t('la-Navigator');
            $block['content'] = $search_text $search_field['content'];
            return $block;
            break;
    }
}

I am new to PHP and I am britty sure that the problem depends on my syntax :-/

2 Answers 2

3

Try the following:

<?php
    $block['content']  = $search_text
    $block['content'] .= drupal_render($search_field['content']);
?>

This way drupal wil render the array for you.

Here is more info about it: https://drupal.org/node/26502

Sign up to request clarification or add additional context in comments.

1 Comment

Altough that works, i must say it is not best practice. You should look in the search module what theme() function they use and process your content array with that. That way you will be able to preprocess it in your theme if needed. But that might come in a later stage in your drupal career ;)
1

For:

$block['content'] = $search_text $search_field['content'];

Perhaps you meant:

$block['content'] = $search_text . $search_field['content'];

3 Comments

when i am trying this, drupal doesnt return me any error, but the output just gives me helloArray, hello is actually the value of the search_text variables
That is because the second variable $search_field['content'] is an array. I'm not familiar with that hook's return, I'll look into that real quick. But the original issue you ran into is that in order to assign two variables to a single one, you have to specify an operator of some sort or run them through a function.
Oh, yup, drupal_render($search_field['content']) as in the other answer. His breaks out the concatenation into two statements. In mine with one line, it would be $block['content'] = $search_text . drupal_render($search_field['content']);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.