Today, the "Submitted by X, on xx/xx/xx" is generated by the theme function theme_node_submitted(). This theme function glue the username and date variable inside a single sentence.
Advanced themers easily know how to override this function but for the average themers it may be very difficult for them to change how authorname and submitted date are presented.
Furthermore, I think that there are many case where authorname and submitted date are not on the same line. For example one may want to put the author name at the end while the submitted date stays at the top of a node.
This is why I propose that we make available the two variables to the node template. Instead of $submitted, we should make available $submitted_date and $author. Therefore even beginners would be able to change how the datas are presented by changing the markup inside node.tpl.php.
This would be done by :
1) Cancelling the theme_node_submitted() function
2) Adding two lines in template_preprocess_node
* One to create the $author variable (if theme settings OK)
* One to create the $submitted_date variable (if theme settings OK)
3) Change the node.tpl.php with a new markup that print "Submitted by $author on $submitted_date"
4) Change node.tpl.php in other core themes
If someone tells me it is not a bad idea I could try to do the patch.
Comment | File | Size | Author |
---|---|---|---|
#74 | 364470-74-submitted-by.patch | 9.44 KB | JohnAlbin |
#69 | 364470-69-submitted-by.patch | 9.51 KB | JohnAlbin |
#65 | 364470-65-submitted-by.patch | 9.54 KB | JohnAlbin |
#52 | 364470-node-submittedby-regression-D7.patch | 6.79 KB | Dave Reid |
#49 | 364470-node-submittedby-regression-D7.patch | 6.72 KB | Dave Reid |
Comments
Comment #1
JohnAlbinI remember this being one of the first things I wanted to do when I learned Drupal theming. And it was too complex to do.
Learning theme() functions is an intermediate-level theming skill. But changing how my name and date appear on my posts is an über-newbie theming desire.
Looks like we should probably use best practices with the t() function when adding this to node.tpl:
<?php print t('Submitted by !author on @date', array('!author' => $author, '@date' => $submitted_date); ?>
Its more complex, which is bad for newbies. :-( But the alternative, unfortunately, would be impossible to translate:
<?php print t('Submitted by'); ?> <? print $author; ?> <?php print t('on'); ?> <?php print $submitted_date; ?>
Comment #2
geerlingguy CreditAttribution: geerlingguy commentedI am definitely +1 on this. I just changed things on stlouisreview.com's articles, and it took me a great deal longer than I would've liked. I ended up trashing the idea of modifying the themeable function, and simply rewriting the PHP in node.tpl.php to suit my desire.
Comment #3
stBorchertAs noted in #382870: Update and Polish Node Template Output I would suggest using an additional template for the output of the submitter information.
Quick proposal (unfortunately I can't create patches from here):
-------------------------------------------------------------------------
Stefan
Comment #4
stBorchertThis patch introduces two new templates:
* comment_submitted.tpl.php
* node_submitted.tpl.php
Comment #5
geerlingguy CreditAttribution: geerlingguy commentedI'm liking it. A lot. Makes it 20x easier to change that text! I would like someone else to RTBC, but I approve wholeheartedly.
Comment #6
catchDoes the phpdoc for theme() need changing (mentions $submitted a few times)?
Comment #7
stBorchertYes, think so.
$submitted
isn't a good example for the use of preprocess-functions anymore.The question is: which one do we want to take instead?
template_preprocess_node
contains"submitted" was the best candidate until now. What about using "classes-array" in phpdoc?
Comment #9
stBorchertRe-rolled because #382870: Update and Polish Node Template Output changed node.tpl.php.
Updated phpdoc for theme() (used $classes-array instead of $submitted).
Comment #10
geerlingguy CreditAttribution: geerlingguy commentedlol - sorry about that business with the node.tpl.php...
Tested, patch applied, seems to function. I'd rather not RTBC, though, as I'm not 100% on the logic—it seems fine to me, but I don't know enough about Drupal to approve committing it to core :-)
Comment #11
tic2000 CreditAttribution: tic2000 commentedI think that creating a new template file just for the submitted part is both too much and not useful. For one if you do it this way you can't, as in OP example, have the date on top and author on bottom of the node or the other way around.
I think JohnAlbin's suggestion is a good one. A proper use of t() inside node.tpl.php. Yes, it may be complex, but I don't think moving it in another file makes themers life easier.
Comment #12
stBorchertSure, you can.
$node
holds exactly this information. And you can put it wherever you like.The intention of this patch was to remove complexity not to add some.
Comment #13
tic2000 CreditAttribution: tic2000 commentedAnd how is this less complex?
Instead of having the function inside node.tpl.php you have to find the file where that $submitted comes from only to find the exact same function you say it's too complex.
What stops you now to use the info you have in $node? The fact that you are new to Drupal and don't know what's inside $node and if you manage to find out you don't know how to convert $node->created to a nice readable date because you are "just" a themer.
IMO this patch doesn't make life easier for new themers to achieve what JohnAlbin mentions in #1.
Comment #14
geerlingguy CreditAttribution: geerlingguy commented@tic2000 - imo, xxx.tpl.php files are much more easy to wrap your mind around for non-programmers (especially those who don't have as much PHP knowledge) than themeable functions. Just my perspective, being a designer/not a programmer.
Edit: Another note... node.tpl.php already has a boatload of logic inside, imo. The less the better...
Comment #15
tic2000 CreditAttribution: tic2000 commented@geerlinguy
You don't get my point. This issue was opened because that $submitted variable is not themer friendly. Now, instead of using t() inside node.tpl.php we use a theme file which has the function inside. So inside node.tpl.php you still have the same $submitted variable. Using another file you don't make $author or $date available inside node.tpl.php so the themer has to learn where he can find that info and how he can transform it in something he can use. This is exactly the situation now, no improvement.
Again a themer won't be able to move $author or $date around. The only minor improvement is that he can now find easier where $submitted is generated.
Themers are not stupid. If they see the t function with !author and $author in it they will figure that out. Figuring out how he can use $author from another template file inside node.tpl.php will require a lot more knowledge.
I, as a themer I would prefer to see the t() in node.tpl.php. It would give me the freedom to move the author or date around. It won't force me to move the whole submitted text around and author and date only inside that text.
If it's not, I would at least like to have $author, $date and even $time_ago available for use in node.tpl.php.
Comment #16
geerlingguy CreditAttribution: geerlingguy commented@tic2000 - the only thing is, I've never seen t() used inside node.tpl.php, and I think we're already starting to see a lot more logic inside of these template files than most non-Drupal themers/designers are used to...
But I get your point; the logic is simply moved to another tpl.php file... it's an interesting dilemma, to be sure. I'd rather vote to keep it separate, just for the sake of keeping node.tpl.php as free of logic as possible, because it's probably one of the template files touched by most new themers, along with page.tpl.php.
Comment #17
tic2000 CreditAttribution: tic2000 commentedIn that case you don't solve the problem pointed in OP and #1.
It can be kept separate, but also add $author and $date and maybe even $time_ago as variables available for node.tpl.php too.
Comment #18
stBorchert@tic2000: the variables already exist in node.tpl.php (and wouldn't be removed by this patch).
Comment #19
JohnAlbinYeah, moving the locked-together variables from a theme function to a template doesn't help much as we usually want to separate them.
We have 6 of them in page.tpl.php. :-)
And t() has to be used if we want any words hard-coded in a tpl because, of course, they have to be translatable from English to the end user's language.
Here's a patch that gets rid of node_submitted and comment_submitted theme functions and replaces them with calls to t().
Comment #21
JohnAlbinUpdated patch fixes broken tests.
Comment #22
stBorchertWhile I really like my solution yours is more simple and looks really good :-).
So RTBC from me.
Comment #23
tic2000 CreditAttribution: tic2000 commentedSince I suggested exactly this solution and the bot likes it too RTBC.
Comment #24
webchickI thought about this patch for awhile...
Displaying the post date without the author is one of the very first things I wanted to do on webchick.net, since -- obviously -- all of the posts on there are by "webchick" so it's redundant to keep repeating it. I was appalled that fixing this meant I had to either hack Garland or make a custom theme (I have since been given a custom theme by quicksketch, so this is more of a moot point now, but still annoying).
So I made #216961: Make author/submitted by separate toggles in the hopes of addressing it. Unfortunately that issue ballooned in complexity as we started really looking into what it would take to fix this; for example the date formats and what not. Additionally, if you start down this road, what DON'T you add a configuration setting for? Why not the div surrounding the submitted-by information too, while we're at it? :P
With this approach, as opposed to the submitted.tpl.php approach, I could at least use the languages override in settings.php to change my formats without hacking the theme. I agree t() in tpl.php files is a little funny, but in this case I think it really does give us the most bang for our buck, and makes it trivial for someone who is cool with theming to jump in here and monkey with stuff.
Therefore, committed to HEAD, and marked the other issue as a dupe. This needs updating in the theme upgrade guides. Well done, folks!
Comment #25
geerlingguy CreditAttribution: geerlingguy commentedHooray! Thank you, webchick!
Comment #26
Danny Englander#21: submitted-no-more-364470-21.patch queued for re-testing.
Comment #27
aspilicious CreditAttribution: aspilicious commentedhighrockmedia this is already committed to head...
It needs documentation + upgrade path I guess...
Comment #29
mariusz.slonina CreditAttribution: mariusz.slonina commentedHm, on the other hand, I tried to create a minimal theme _without_ touching default template files, as described here: #812796: Theme API feels to be incomplete. I added there a patch also for... restoring $submitted (as I didn't found this topic before), because it allows me to change submitted message hardcoded right now in node.tpl.php or comment.tpl.php without overriding these files. To have completely rewritten submitted message without using custom node.tpl.php I need to translate the string, right? (which I don't want to do, and I feel it is not the way...). With some kind of "submitted" variable I am able to produce theme, that will include only 4 files: info, reset.css, style.css and template.php with all flexiblility of the theme api. Having all other variables not hardcoded in template files -- and only submitted message hardcoded -- seems a little bit strange for me, just because I learned that Drupal is very flexible. As a "local" themer, webdeveloper and software engineer I miss $submitted variable, it was for me much more cleaner, and "compact" to adjust it in the template.php.
Comment #30
Adam S CreditAttribution: Adam S commented#9: 364470_submitted-9.patch queued for re-testing.
Comment #31
Jonah Ellison CreditAttribution: Jonah Ellison commentedI've been working with the Zen 2.0 theme and discovered they already backported this patch to Drupal 6, which was a rather frustrating experience. I agree with mariusz -- I miss $submitted. I was hoping to make my Zen subtheme small and compact, but I had to copy over node.tpl.php for a simple text change.
This patch makes node rendering less modular, since the template file "owns" the submitted text. If someone had a module that required changing the node submit text, they can no longer do this through preprocess hooks. Even the theme's own template.php file cannot change the text.
I don't agree with this patch for the sake of making it easier for newbies while sacrificing the modular nature that makes Drupal so great.
Comment #32
Dave ReidWith this patch we removed flexibility in being able to edit the submitted by information on specific node types or nodes, rather than globally, which is what a settings.php language override would do... We now have to hack core to be able to truly change this.
Comment #33
NancyDruArgghhh!!! This whole thing is a bad idea!!!
Submitted By gives users the total flexibility of Tokens and changing the string by content type. And the module was even originally created by a core maintainer.
This is a huge step backwards. Please consider backing this whole thing out.
Comment #34
Dave ReidUpgrading this to major. This needs some responses from those working on the initial patch as to how we can solve this.
Comment #35
Dave ReidComment #36
NancyDruDo a search on theme_node_submitted and you will see many posts where users have developed sites based on that function. All of their sites will go down the drain. I have no idea how many themes will be broken.
Comment #37
tic2000 CreditAttribution: tic2000 commented@mariusz
As you noticed in that issue you have to actually add or change a lot of stuff to get a simple theme. And that supposing the markup in the default files is everything you want, which rarely is, which means yours is an edge case.
@Jonah
So you install a theme (Zen) and create a subtheme, but yo have a big issue with the fact that you need to add node.tpl.php to your theme. Well, that's not compact anyway.
@Dave
No we didn't. How could you edit $submitted before? Preprocess hook in template php or a node.tpl.php file for each node type. You can do both now. With the preprocess hook you will need to change that t() back to $submitted and create the $submitted variable in the preprocess hook for each node type like in D6.
@Nancy
You talk about a module that for multi language sites needs the settings.php technique to translate the output.
I searched like you suggested and I did not see those issues with sites "based on that function". And even if they based their sites on that function the change they will require, like I already explained to Dave, should be trivial, so it will not throw their sites down the drain.
The issue was to make that variable easier for themers. That's one think a lot of new Drupal users try to do and it was not easy. Even for a developer new to Drupal it was not easy. It required more time than it does now.
This is by design. It's not a bug, and it's not a regression.
Comment #38
tic2000 CreditAttribution: tic2000 commentedComment #39
Danny EnglanderI am not sure if this is relevant (or offers enough flexibility) but I typically do something like this in my node-custom.tpl.php. That seems fairly "easy" to me as a front end developer / themer. :)
...and then of course however you want to do CSS for the above -- I have attached a screen capture how it looks on my website.
Comment #40
NancyDruYou do understand that there will be no $submitted with this change? In 6.x you don't have to do that at all if you recommend the Submitted By module to your users, which gives people the opportunity to change the submitted by line for each content type in any way they like. This partially committed change is a big step backwards in theming IMHO.
@tic2000: if Submitted By is not working the way you think it should, then please submit a feature request (preferably with a patch). This is not the place to discuss that issue.
Comment #41
Jonah Ellison CreditAttribution: Jonah Ellison commentedtic2000, the argument is that we want the submitted by text to remain modular and flexible.
For example, if a site is using Garland and the user wants to change the submit formatting, this can't be done without hacking core due to this patch.
Part of successful Drupal theming is learning template variables, theme override functions, and preprocess hooks. I'd rather that newbies learn how to properly theme Drupal elements instead of giving an easy way out like this.
Comment #42
NancyDru"An easy way out" that will come back to bite them later.
In all the sites that I have developed, I can count on one hand the number of times I've had to resort to a node-xxx.tpl.php, which I would believe I would be doing a lot of with this "improvement."
With all my modules, I often get posts from people who claim they can't code, but are happy (even desire) to theme various elements. I absolutely agree with Jonah on his statement.
Comment #43
webchickIt sounds like those advocating for a roll-back have presented some pretty compelling evidence that we lost a lot of flexibility with this change. I agree that copy/pasting a bunch of node-XXX.tpl.php files around for the purposes of changing one line of code is sub-optimal.
JohnAlbin, geerlingguy, do you have a response?
Comment #44
Dave ReidMy proposal is to make just a simple change to the default node.tpl.php to allow $display_submitted to be a string that is inserted directly, but also support the true/false logic with the default string.
Comment #45
NancyDru@Dave: how is that different from the D6 $submitted variable? Most themes use that today, and those that don't were slowly getting the religion.
@Angie: not just "changing one line of code," but one line that is easily themed and/or altered to the user's desires. Not to mention in use on many sites (do a search on "submitted by") that would now have to change one more thing in order to get to D7.
I certainly don't mind presenting more variables to the templates but you open a can of worms: "You added xxxx. so why not yyyy?" and "Why not just pass every token that's available?" (You have know that will come probably sooner rather than later.)
Comment #46
webchickWell. If we're going that route...
a) It should revert back to the old name $submitted.
b) It needs to be documented in node.tpl.php.
c) We should set it up somewhere in theme.inc/node.module.
Comment #47
JohnAlbinSo, I see this issue as a pendulum thing. Before the $submitted_by variable was non-obvious to change by themers. This fact drove the development of modules like NancyDru's, since it was relatively easy for modules to change the variable.
Now in d7, we've gone to the other extreme (unintentionally), themers can easily see how to change this text, but modules are completely shut out. That was not my intention with the original patch, btw.
I'm okay with davereid's compromise. It is slightly icky in that it checks for is_string() in the template, but it does provide for both themer and module developer modification of the text.
Comment #48
Dave ReidFeels like we should just make the submitted by information just work like everything else in the templates, and just add it using preprocess. No crazy theme functions just for the submitted by information, but anyone would have to learn how to use preprocess properly to override any of the other variables, so I think this makes a lot of sense.
Comment #49
Dave ReidAck, extra hunks not removed from that patch.
Comment #50
Dave ReidThe only downside to this is Bartik doesn't use this at all and splits its information up into a separate paragraphs for username and date, but that's a downside regardless of this patch.
Comment #52
Dave ReidComment #54
Dave Reid@all: Does the solution in #52 seems reasonable for me to proceed rolling it?
Comment #55
Dave ReidComment #56
NancyDruI haven't tested it, but the code looks like it should take care of my objections and keep the Submitted By module working.
Comment #57
Dave ReidBumping to major.
Comment #58
NancyDruPersonally, I would mark it as "release blocker."
Comment #59
jensimmons CreditAttribution: jensimmons commentedsubscribe
Comment #60
Dave ReidThis indeed is something that *has* to be fixed before 7.0.
Comment #61
geerlingguy CreditAttribution: geerlingguy commentedAh crud. /me slaps himself in the face. After 1.5 years, I disagree with pretty much everything I said in the first replies. I'm all for Dave's use of preprocess functions. Don't have time right now to test this patch, though.
Comment #62
Dave ReidCould also use some help figuring out why the rdf_test module suddenly fails with this.
Comment #63
Dave ReidOH %@^@$#... rdf_process() and rdf_preprocess_node() both have to run after template_preprocess_node() somehow. This sucks.
Comment #64
JohnAlbinI see how to fix the RDF issue. Rolling a patch now. Temp work at https://github.com/JohnAlbin/drupal/tree/364470-submitted-by
Also, Dave's patch obliterates both Garland's and Bartik's preferred language around the name and date variables.
Comment #65
JohnAlbinUpdates since patch in #52:
Since this tweaks a translation string, I'm bumping this to critical so it goes in before RC1 (string freeze).
Comment #67
tim.plunkettsub
Comment #68
JohnAlbinWhat the… I fixed the RDF issue, but borked the upgrade path??? /me scratches head and investigates.
Comment #69
JohnAlbinha! I used $variables instead of $vars in Garland's template.php. Stupid Garland. Someone should fix that inconsistency. Oh, wait. #975168: Add JohnAlbin to MAINTAINERS.txt Crap.
Anyways, here's an updated patch.
Comment #71
EvanDonovan CreditAttribution: EvanDonovan commentedI am so glad you are adding $submitted back in. Preprocess seems like the most logical place to generate it, and would allow you to modify it on a node-type basis.
Comment #72
JohnAlbin#69: 364470-69-submitted-by.patch queued for re-testing.
Comment #73
tim.plunkettRemoving
$display_submitted
breaks the ability to easily override$submitted
in a template_preprocess_node(), because if you override it will print regardless of the node setting. Otherwise you'd have to foreach over'node_submitted_' . $node->type
every time, which would be bad DX (TX?).Comment #74
JohnAlbinI agree with Tim. The patch in #69 demonstrates that it is very easy for a themer to forget to check that variable before creating a new $submitted value. Unintentionally in that patch, I made both Bartik and Garland always output the $submitted variable even if the node submitted by display setting was off.
Here's a new patch that adds $display_submitted back in.
Comment #75
JohnAlbinOops. misread webchick's comments about string freeze changes. should be tagged "string freeze" but left at major priority.
Comment #76
JohnAlbinAs a themer, this isn't a critical issue since I can easily modify what I need. I would prefer the patch to what's in D7 now, but if it doesn't get in I won't be greatly annoyed. (unlike for some issues)
For those who consider this essential to d7, review! Time's a wastin'. 1 week until RC1. tick. tick. tick.
Comment #77
Dave ReidDon't these preprocess functions completely negate any changes made by modules to $vars['submitted']?
Same
Powered by Dreditor.
Comment #78
JohnAlbinNot if the module is smart and does its work in MODULE_process_node() and MODULE_process_comment(). :-D
Comment #79
mariusz.slonina CreditAttribution: mariusz.slonina commentedThank You for work on this issue. I applied the patch and rebuild my custom theme with $submitted variable -- it seems to work nice and it is much much closer to css-only theme with many things overridden with template functions in template.php :) As a simple test, I also added a template.php to Stark, and used preprocess functions for node and comments to achieve custom $submitted. It's a flexible solution, as in my opinion should be :)
Comment #80
EvanDonovan CreditAttribution: EvanDonovan commentedJust from looking at the code this looks like a clean solution. I'd like to mark RTBC, but I don't have the time right now to actually test by modifying a theme.
Comment #81
tim.plunkettThis is ready. And it makes so much more sense.
Comment #82
webchickI really hate to make a change like this this late, but the evidence for rolling back is pretty compelling, even coming from the original authors.
So, committed to HEAD.
Please formulate exactly what changed here so that Randy can announce to the dev list.
Comment #83
NancyDruYay, thanks, Angie.
Comment #84
rfayYes, if this is an API change that could affect existing code, please summarize here so it can be announced.
Thanks!
Comment #85
JohnAlbin@rfay:
Previously in D7, the "Submitted by…" text for node and comment tpls was created with a t() function that resided directly in the node.tpl.php and comment.tpl.php. With this API change, the node's $name and $date variables are joined together inside template_preprocess_node() and printed as a $submitted variable in the node.tpl.php. The comment's $author and $created variables are now joined together inside template_preprocess_comment() and printed as a $submitted variable in the comment.tpl.php.
Comment #86
NancyDruAnd, this means that "Themes should become more consistent is using the $submitted variable rather than creating their own. This, in turn, allows site maintainers greater flexibility in controlling the submitted-by line."
Comment #87
jhodgdonNeeds to be added to the 6/7 theme and module update guides too, right?
Comment #88
Dave ReidYes it should, considering the first time this was changed, it didn't make it in the upgrade guide either...
Comment #89
jhodgdonChanging the tag. As of now, we are using the tag "Needs Update Documentation" to designate issues that need documentation in the 6/7 update guides (module or theme).
Comment #90
polishyourimage CreditAttribution: polishyourimage commentedsubscribing
Comment #91
Frank Pfabigansubscribing, +1
Comment #92
Anonymous (not verified) CreditAttribution: Anonymous commented+1...
Comment #94
davidsanger CreditAttribution: davidsanger commentedSo if the change has been made how do I change the "submitted by" text in Drupal 7 ?
Comment #95
jhodgdonComment #85 has an issue summary. It still needs to be documented in the theme and module upgrade guides.
Comment #96
dantje CreditAttribution: dantje commented@davidsanger:
What worked for me:
Currently in Bartik's node.tpl.php the following code appears:
<?php print $submitted; ?>
In order to display the author name only, I replaced it with:
<?php print $name; ?>
And you can add the "posted by" if you like:
<?php print 'Posted by ' . $name; ?>
And for the date only add:
<?php print $date; ?>
(I couldn't find where to change the "posted by" not in an overriding nature like the method above, I'm quite new to the coding aspect... Maybe there's a cleaner way).
Comment #97
jhodgdonJust as a note - the issue summary in #85 is misleading -- that tells what happened late in this issue, not what changed between d6 and d7.
What really has apparently changed between D6 and D7 in relation to the $submitted variable is that in D6, it was created in template_preprocess_node by a call to theme('node_submitted'), and in d7, it is created in template_preprocess_node by
So I don't really think this is much of a 6/7 API change. The separate $name and $date variables existed in d6 as well. The only API change between 6 and 7 is that theme_node_submitted no longer exists.
I've documented this in:
http://drupal.org/update/themes/6/7#submitted_by
I don't think it deserves a mention in the module update guide, so I think this is done.
Comment #100
gurtner CreditAttribution: gurtner commentedThanks, @jhodgdon your comment gave me exactly what I needed!
I posted my solution at https://groups.drupal.org/node/132554#comment-1048128