Currently there is no theme function explicitly defined to theme the "Submitted by on ". Raw text is assigned to the phptemplate variable directly and passed to node.tpl.php. Providing this theme function allows people to theme this directly.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

drumm’s picture

Status: Needs review » Needs work

This will have to be called from the defualt theme_node() over in theme.inc.

Why would the node object passed to that ever be empty?

zirafa’s picture

FileSize
2.22 KB

I guess you are right, there shouldn't be any reason that node would be empty. Will change.

Is this the section that needs to be changed in theme.inc?

function theme_node($node, $teaser = FALSE, $page = FALSE) {
// snippet
  if (!$node->status) {
    $output  = '<div class="node-unpublished">';
  }

  if (module_exists('taxonomy')) {
    $terms = taxonomy_link('taxonomy terms', $node);
  }

  if ($page == 0) {
    $output .= t('!title by !name', array('!title' => '<h2 class="title">'. check_plain($node->title) .'</h2>', '!name' => theme('username', $node)));
  }
  else {
    $output .= t('by !name', array('!name' => theme('username', $node)));
  }

// end snippet
}

Change it to:


  if ($page == 0) {
    $output .= '<h2 class="title">'. check_plain($node->title) .'</h2>';
  }
  
  if ($submitted) {
    $output .= theme('submitted', $node);
  }

Or am I misunderstanding? If so, I've submitted a revised patch with the changes.

zirafa’s picture

Status: Needs work » Needs review
eaton’s picture

Status: Needs review » Needs work

The code is nice, the solution is zero-impact, and it lets us control something that is a pita to override currently. Three cheers! Shouldn't:

+function theme_submitted($object) {
+  return t('Submitted by !a on @b.', array('!a' => theme('username', $node), '@b' => format_date($node->created)));
+}

be

+function theme_submitted($object) {
+  return t('Submitted by !a on @b.', array('!a' => theme('username', $object), '@b' => format_date($object->created)));
+}

Or am I missing something..?

zirafa’s picture

FileSize
2.16 KB

Wow, that's a dumb mistake. Updated patch.

zirafa’s picture

Status: Needs work » Needs review
drumm’s picture

Changed !a and @b to words.

Changed $object to $node.

Changed around the logic on theme_node(). $submitted wasn't set and I think we always want this.

drumm’s picture

FileSize
2.51 KB

.

zirafa’s picture

Looks good and is easier to read now, too.

zirafa’s picture

Was this ever committed?

eaton’s picture

Status: Needs review » Reviewed & tested by the community

Nope, it wasn't. But it should be. ;-)

This is a small but extremely useful improvement for themers, and it breaks no existing theme code.

merlinofchaos’s picture

Much +1 from me. This should definitely go in. Because this isn't a bug or a task we'll probably have to prod the committers to give it attention.

RobRoy’s picture

FileSize
2.51 KB

There was an undefined $object->created in there when it should have been $node->created. Looks good now.

Steven’s picture

Status: Reviewed & tested by the community » Needs work

I think we need to step back and look at things from a little further.

Changing that ugly "Submitted by" line is probably one of the first things I do in any of my themes... and I'm sure plenty of designers out there do too. With this patch, you have to create a special submitted.tpl.php file or create a theme override in template.php. That is too much work for such a simple and common tweak.

Why not get rid of $submitted completely and just paste in the literal code in the node.tpl.php? That's where it belongs, and where themers will most easily find it.

Also, that non-sense of t('!title by !name', ...) vs t('by !name') really needs to go. Having two different t() strings for the same thing is bad and only leads to inconsistencies. It is also in theme_node(), the one themable function which is going to be overrided in 99.9999999% of all cases.

eaton’s picture

Changing that ugly "Submitted by" line is probably one of the first things I do in any of my themes... and I'm sure plenty of designers out there do too. With this patch, you have to create a special submitted.tpl.php file or create a theme override in template.php. That is too much work for such a simple and common tweak.

I'm not sure I agree. Consolidating this bit of code into a theme function is simple and straightforward: overriding it via mytheme_foo() {} is easier than overriding it via the phptemplate_variables function, and it prevents needless bloating of the node.tpl.php file. Nothing prevents themers from sticking custom code in node.tpl.php now, but $submitted is a well-defined and often-used variable now.

Keeping it as is, that's one thing. Making it a theme function, that's better... But I don't see how *removing* the $submitted variable entirely accomplishes anything other than breaking existing themes needlessly?

Steven’s picture

You misunderstood. I meant replacing print $submitted; with if ($submitted) print t('Whatever goes here'); , right in the node.tpl.php. Much easier to edit.

RobRoy’s picture

Let's just do both. Get the theme('submitted') in there so if I have 10 different "node-type.tpl.php"s I can just do an

if ($submitted) { print $submitted } 

in all 10 files and one change to my template.php's phptemplate_submitted() will change all of them.

And if I want to customize it in my theme (or the theme designer wants to have it customized) I can just replace print $submitted with t('Whatever goes here'). True, I'll have to look up theme_submitted to see what to put in there, but it's still pretty easy as far as edits go.

Steven’s picture

Having to look up the theme('username') and format_date() calls is far from easy, while inserting $submitted is trivial.

Plus, if you have multiple node-type.tpl.php files, that is because you derived them from one and the same node.tpl.php file, and you probably made that change early in the process.

zirafa’s picture

Why not get rid of $submitted completely and just paste in the literal code in the node.tpl.php? That's where it belongs, and where themers will most easily find it.

This will break a lot of themes. But I think this is fine if we provide smaller variables for theme('username') and format_date.

something like:

$user_name = theme('username');
$date = format_date($node->submitted);

That way themers can do the following directly in node.tpl.php:

Submitted by <?php print $user_name ?> on <?php print $date ?>

And allows themers to really play around with the formatting much more. Steven is this what you were getting at?

jetsetter’s picture

Zirafa et al:

I am dealing with wanting to simply not have a clickable author link in the middle of my theme development, and your proposed change to the node.tpl.php:

> Submitted by print $user_name on print $date

Is exactly what I was looking for before I realized I would have to go to much more trouble to change this. Here's a +1 for that idea.

coreb’s picture

Version: x.y.z » 4.7.x-dev

Moving out of the "x.y.z" queue to a real queue.

RobRoy’s picture

Version: 4.7.x-dev » 5.x-dev

Should be 5.x at minimum.

dmitrig01’s picture

Version: 5.x-dev » 6.x-dev

No more stuff goes into 5.x

Pancho’s picture

Version: 6.x-dev » 7.x-dev
Assigned: zirafa » Unassigned

Still not fixed - I guess this will be for D7...

kbahey’s picture

Version: 7.x-dev » 6.x-dev
Status: Needs work » Closed (duplicate)

Already fixed.

Duplicate of #146386.

omnyx’s picture

Hi all - I hope this is related to what you're discussing.
I have two regions (two blocks) next to each other and I use each to occupy exactly 1 node (news node). But those two nodes have text of different length - I would like to have the $submitted info to go to the very bottom of the region/block.
It doesn't look nice to have submitted/read more of one node not in line with that of another, if they are sitting next to each other.

an example: www.theonion.com see how the recent news tab (to the middle left of the screen) has the two dates aligned regardless of the text length.

I assume this is a theming issue. Could anyone know what I could do about it?

thanks a bunch

foresttb’s picture

hello.
i need to change the username and instead use a profile_displayname (added extra).
just for the particular template(amity_island) is needed.(by modifying node.tpl.php -> echo $submitted)
how may i do that?