0

As i am still developing some basic php skills:

I want to theme the title of my views-block slightly (just color and fontweight)

I have created a views-view--my-view--block-1.tpl.php and pasted the code of the 'display output' under the theme information of my view.

However i am stuck here as i cant seem to find anything that looks like a block title variable.

I have looked in my block.tpl.php but dont know what code to use here.

Help appreciated,

2 Answers 2

0

You can achieve what you have stated in several different ways. The easiest and straight-froward would be:

Right click on the title, select Inspect element and then find the default CSS classes that represent the generated view and the css class for the element (usually h2 tag) and apply your custom CSS to it.

You can also install/enable the Devel Themer module that would provide you more information about every section of your page. Let's say you want to know which template file exactly renders a particular, click on that section and the devel themer would display the template file that is being used. Don't forget to disable the module, once you are done.

Make sure that you clean the cache whenever you make changes to the template files, either the theme registry cache or the 'all'.

You can also add CSS directly to the tag inside the template file that would look something similar:

 <?php if ($title): ?>
    <h2<?php print $title_attributes; ?>><?php print $title; ?></h2>
  <?php endif;?>

Or you can style the above in your template file.

1
  • As i had trouble (missing skills) applying the css in my tpl.php file. I ended up solving it by changing th css class. Thanks!
    – Byron
    Sep 1, 2014 at 9:57
0

Have a look on the original template on modules/block:

<div id="<?php print $block_html_id; ?>" class="<?php print $classes; ?>"<?php print $attributes; ?>>

  <?php print render($title_prefix); ?>
<?php if ($block->subject): ?>
  <h2<?php print $title_attributes; ?>><?php print $block->subject ?></h2>
<?php endif;?>
  <?php print render($title_suffix); ?>

  <div class="content"<?php print $content_attributes; ?>>
    <?php print $content ?>
  </div>
</div>

As you might see in line 4 there is a

<?php if ($block->subject): ?>    
<h2<?php print $title_attributes; ?>><?php print $block->subject ?></h2>
<?php if ($block->subject): ?>

Use this... but do not forget to use

<?php print render($title_prefix); ?>

before the title and

<?php if ($block->subject): ?>

after the title - these variables enable contextual links.

Additionally assure that you follow the template naming conventions. I think it should be views--view--my-view--block-1.tpl.php (but I am not sure - did you alreay find out if your template file is used? To do this just add any text into the file to see changes in the browser).

When you just added a new template file remember to rebuild theme registry. Either by deleting all Drupal caches or by visiting admin/appearance. If you use Devel module in conjunction with Admin menu you find a possibility to rebuild the theme registry under the projects favicon on the left of the Admin menu.

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.