0

I am new to drupal and I am wondering how to gain more control over a view block. Currently I am embedding my view block in my page by doing :

<?php print views_embed_view('news_overview', $display_id = 'block'); ?>

This works but if I want to style this further I have to go into my view and format it as content and add the html templating there which leaves me with a bit less control than I want.

I made a views-view--block.tpl.php file to try and style my view block a bit more but I am left wondering how to render single view fields here.

I tried doing this to for example render a body field:

<?php foreach($view->result as $object): ?>
    <?php print render($object->_field_data['nid']['entity']->body['und'][0]['value']); ?>
<?php endforeach; ?>

Ofcourse doing this for each field is a hassle and I was wondering if there is an easier way to output view fields inside my views-view--block.tpl.php template.

Cheers.

  • Why not just remove the fields you don't want to show and only leave the Body field? Or if you want different variations, just make a new block display on the same view and adjust accordingly. Also you can do "Field Templates" if you want to style a particular field in a certain way. Click on "Theme: Information" link on "Advanced" dropdown of your views display when editing. – Beebee Feb 15 '16 at 10:31
1

The first thing do not use that tpl file(views-view--block.tpl.php), this will alter all views of your current system. you can use views-view--news-overview.tpl.php this will alter your current views view only, there is many suggestions in views->advanced->theme:information. you can use appropriate tpl file.

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.