For some reason, the block module prints the title (subject) directly out of the block object
<?php if ($block->title): ?>
<h2<?php print $title_attributes; ?>><?php print $block->title ?></h2>
<?php endif;?>
instead of having a nice, easy-to-read title variable for use in the block template, like nodes.
<h2<?php print $title_attributes; ?>>
<a href="<?php print $node_url; ?>"><?php print $title; ?></a>
</h2>
Also related #1591806: Change block "subject" so that it's called a (admin_)label like everything else on the theme layer.
Comments
Comment #1
jenlamptonThe more I think about this, I think we should backport it to 7 too. All old themes will still work since block will still be available in the template files for printing the old way, but we can still make new people happy by being consistent :) win win!
Comment #1.0
jenlamptonupdated indenting
Comment #3
nielsonm commentedHere's the patches for D8 and a backport for D7.
Comment #4
nielsonm commentedComment #6
nielsonm commented#3: provide_block_title_for_template-1591832-3.patch queued for re-testing.
Comment #8
mjonesdinero commentedComment #9
mjonesdinero commentedHere's an updated patch for D8..
Comment #10
mjonesdinero commentedComment #12
mjonesdinero commentedanother update
Comment #14
mjonesdinero commentedanother format..hopefully this will be okie
Comment #16
mjonesdinero commentedComment #17
mjonesdinero commentedhopefully this one will work now..sorry for to many failed this just want to make my first commit in d.o
Comment #19
mjonesdinero commentedops, seems i have to study more before attempting a patch again..
Comment #20
mjonesdinero commentedAnother try.. test this in my clone d8 in my local..hope this will be okay now
Comment #21
jenlamptonWorks great for me, thanks for working on the patch :)
Comment #22
catchHow does this fit in with #1591806: Change block "subject" so that it's called a (admin_)label like everything else on the theme layer?
Not sure if this is backportable or not - it's a "data structure addition", if it is then I don't object to it going into 8.x first, but assigning to David since I'd rather go with #1591806: Change block "subject" so that it's called a (admin_)label like everything else on the theme layer for 8.x and close this altogether if not.
Comment #23
David_Rothstein commentedAs much as I'd like to see this in Drupal 7, I'm not sure it's actually safe for backport. The first part of the patch is a "data structure addition", but the second is really a "data structure change". It replaces $block->subject with $title assuming they're the same thing, but they could easily have been altered along the way.
For example, what if someone has code like the following (I see this kind of thing pretty often):
This patch will break that, because the alteration to $block->subject will never be used in the template.
Comment #24
mjonesdinero commentedSo, guys what are we going to do with this?
Thanks for your feedback here,
I am a beginner and hope to have my first commit in drupal.
Comment #25
David_Rothstein commentedI'm sure it will happen soon, @mjonesdinero - good luck!
I think the first half of the above patch (which just makes the 'title' variable available) is safe for Drupal 7, if we only wanted to do that... It's less exciting if we can't actually use it in the core templates, but at least we could document its availability. Not sure if it's actually worth doing that.
Otherwise, unless my example above is wrong, we can't do much here for Drupal 7, but for Drupal 8, the patch at #1591806: Change block "subject" so that it's called a (admin_)label like everything else on the theme layer is definitely a good way to go and a more comprehensive solution to the problem, and that patch still needs people to help work on it a bit more.
The change to a straight $title in the template (rather than $block->title) in Drupal 8 could either happen as part of that issue or here as a followup, I guess.
Comment #26
mjonesdinero commented@David_Rothstein thanks for that feedback.
this will add some knowledge on my self.
Comment #27
David_Rothstein commentedIt occurred to me that another way to achieve the goal of this issue (in Drupal 7) might be something like #1158090: Separate usage of hide(), render(), and other template features from print statements to enable non-developers to create themes . Since that issue would move all the ugly logic in PHP templates to the top of the file, out of the way of the HTML, and something like
$title = $block->subject;could definitely go at the top with the rest of the ugly stuff, so that $title could then be used in the actual main part of the core template.That's a big issue, and I had been meaning to get back to working on it at some point, but then I started maintaining Drupal core which took up my time instead :)
Comment #28
jenlamptonI still think this and #1591806: Change block "subject" so that it's called a (admin_)label like everything else on the theme layer are two separate issues. That other one is renaming the thing everywhere it exists, but if we stop there then the block template will still print it's subject/title directly from the object instead of using a nice friendly variable. So for D8, I think we should pursue this solution. (changing status back)
For D7, maybe we should hold off until we have a chance to work on #1158090: Separate usage of hide(), render(), and other template features from print statements to enable non-developers to create themes but yeah, if we can get all the complex structures turned into strings in the template files themselves, then changes made in a theme's preprocessor would still cary across - and this issue won't even need a backport. (removing tag)
Comment #29
mjonesdinero commented@jenlampton
Thanks again with your feedback..so what are the next step that we will make with this issue?
Comment #30
webchickI'm going to throw this in catch's pile, as I'm not sure exactly what he wants to do here.
Comment #31
catchSince David doesn't think this can be backported, I'm going to mark this as duplicate of #1591806: Change block "subject" so that it's called a (admin_)label like everything else on the theme layer, hopefully we can get the patch over there moving.
Comment #31.0
catchchange related text