Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I want to get a <br> tag into a block-title but by default the brackets are turned into html characters. My theme's block.tpl is

<h2<?php print $title_attributes; ?>><?php print $block->subject; ?></h2>

so it looks like the rendering isn't happening there. I can't find where $block->subject is getting processed. It's not in my theme's template.php. So where in core is $block->subject assembled?

share|improve this question

3 Answers 3

You may be interested in Block Class Styles, which has an additional feature:

Allows the ability to set a global text format for custom block titles; this allows you to now have HTML in your custom block titles. Yes, you can now have block titles that contain HTML markup!

share|improve this answer

Found the line in block.module:

$block->subject = $block->title == '<none>' ? '' : check_plain($block->title);

Decided to skip any fanciness and just replace $block->subject with $block->title in my block.tpl.php. Easy.

share|improve this answer
2  
careful. Core does this to disallow HTML in block titles -- this is to avoid an authorized user from creating content that contains HTML to cross-link titles to malicious domains. –  tenken Jan 14 '13 at 19:25
    
Thanks, yes. This is for a site with only trusted users. Is there a better filter for html that still lets <br> tags through? –  alexvance Jan 14 '13 at 19:40
3  
Drupal doesnt care about "trusted users". It assumes everyone is potentially malicious -- because your site could be hacked and an un-trusted user could submit a blog post, or create a block for instance. Dont get me wrong -- I've done something similiar for a project as well. As a CMS drupal sanitizes all "titles" that come from user input. –  tenken Jan 14 '13 at 20:05
    
Right, that's what I meant - the users are trusted by me, not necessarily Drupal. :) –  alexvance Jan 14 '13 at 20:27

i went this route without having to hack core or install another module. this solution is good if you just need to insert a limited amount of html. in my case i just wanted to surround the text with an em> tag for styling purposes.

i made a new tpl file to override block.tpl.php in my templates folder and I added in the following:

<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 

  $xtitle = preg_replace('/\*\*/', '<em>', $block->subject, 1); 
  $xtitle = preg_replace('/\*\*/', '</em>', $xtitle, 1); 

  print $xtitle; 

  ?>

  </h2>
<?php endif;?>
  <?php print render($title_suffix); ?>

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

All I'm doing is just doing a string replacement for * * . Now i can just surround my titles with ** if i want to add the em> tag.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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