0

I am new to Drupal and slowly getting my head around it. I'm using Pay to Publish module on my site, I've setup a custom block that gets recent posted advert (very simple) now I want to style the block to look a bit different which isn't too hard. I've managed to create a new .tpl.php for my specific block. However past here I cannot figure out how to gain access to the variables for each post. This is what I have currently and what I want: http://gyazo.com/e91c01cd9b64d4a31a01c9e5039c7362

So i'll need to gain access to the price and picture url from each post. If anyone can point me in the right direction that would be great, being new to Drupal I'm not entirely sure I've been using the right keywords in my searches on Google.

Much appreciated, Ross.

1

1 Answer 1

1

You can create custom block and you can render variables using block view function

function MODULENAME_block_info() {
    $blocks = array();    
    $blocks['top_five_adverts'] = array(
        'info' => t('Top Five Adverts'),
    );
}

function MODULENAME_block_view($delta = '') {
    $block = array();

    switch ($delta) {
        case 'top_five_adverts':
            $block['subject'] = '';
            $block['content'] = theme('top_five_adverts_list', array('data' => getAdverts()));
            break;
    }
    return $block;
}

function MODULENAME_theme() {
    return array(
            'top_five_adverts_list' => array(
            'variables' => array('data' => null),
            'template' => 'theme/top_five_adverts_list',
        ),
    );
}

Create top_five_adverts_list.tpl.php in theme folder of that module

1
  • Thanks for the answer, had a quick go of it to no avail but while I was swapping menus etc I discovered I could add fields to the block type so I added my display picture and price fields. From there Drupal allowed me to add style classes to my rows (individual items in this case) and with a bit of tweaking to my css I managed to get the styling bang on. Commented Mar 24, 2014 at 15:32

Your Answer

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

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