Is there a non programmatic way to override the NODE TITLE text
- on a per node or
- per node type basis

such as: - for example - the BLOG TITLE text when a blog is displayed, where the default would be:

blog

that I want to replace with an arbitrary text string instead?

A similar example occurs when displaying the root blogs page at the URL 'blog' where the title begins simply 'blogs'

------------

I noticed that the consequences of the 'title' for a blog are the product of a hard coded text string within the file blog.module - as follows:

/* line 127 */
if ($account->uid) {
drupal_set_title($title = t("%name's blog", array('%name' => $account->name)));

------------

Is there something in the administration user interface or some other made of overriding the output text of the drupal_set_title() function?

Is there some other alternative means of doing this?

Is there a contrib module that enables some workaround to this problem?

(There appear to be other similar issues with hard coded strings like this in drupal. -- ??? -- )

Is there some view of the architecture regarding this kind of override/customization I might be missing?

Comments

somes’s picture

Have you seen node theming this will probably get you what your looking for

http://drupal.org/node/44699

sprite’s picture

Thank you for the pointer to the node theming article.

I guess the basic logic below:
( to breakout details for each page and node type)

could be accomplished with both the page and node types making

page*.tpl.php and node*.tpl.php files for each node type.

... but it is a very programmatic hack - while this is supposed to be CMS world - designed reduce/eliminate all that.

-----------------------

if ($is_front) {/* check if it's the front page */
    include 'page-front.tpl.php'; /*load a custom front-page.tpl.php */
    return; }
if ($node->type == 'book') {/* check if it's a book page */
    include 'page-book.tpl.php'; /*load a custom book-page.tpl.php */
    return; }
if ($node->type == 'blog') {/* check if it's a blog node */
    include 'page-blog.tpl.php'; /*load a custom blog-page.tpl.php */
    return; }
if ($node->type == 'image') {/* check if it's an image node */
    include 'page-image.tpl.php'; /*load a custom image-page.tpl.php */
    return; }
if ($node->type == 'forum') {/* check if it's a forum node */
    include 'page-forum.tpl.php'; /*load a custom forum-page.tpl.php */
    return; }
include 'page-default.tpl.php'; /*if none of the above applies, load the page-default.tpl.php */
    return; }

spritefully yours
Technical assistance provided to the Drupal community on my own time ...
Thank yous appreciated ...

somes’s picture

you logic is correct but you wouldn’t make all those calls anyway

your logic above is the general layout of the page and not the individual nodes themselves

Really beyond what is suggested you can use the API to selectively make the individual calls to the data base but that seems a waste with what is currently available though drupal then again it really depends on what you are trying to achieve, take a look and see if your over complicating matters

you should create node-blog.tpl.php then add your “blog” title where the title is called
the word blog would appear on all blog pages where the title is (I think thats what your trying to achieve)

If that helps
later

heine’s picture

There appear to be other similar issues with hard coded strings like this in drupal.

I've already told you in another thread:

If a translation is loaded, t() translates this string.

You can exploit localisation to make site-specific strings.
Enable locale, export all drupal strings to a .pot file (or download one http://drupal.org/project/Translations), add a new 'language' and import the po file (renome the .pot) as the new language.*

Now you can use the administration interface to modify strings for you new 'language'. An alternative is to edit the pot file (poedit) prior to import.

* Some details may be missing; I've never done this, because I already use a translation.

--
Tips for posting to the forums.
When your problem is solved, please post a follow-up to the thread you started.

sprite’s picture

First of all you did not pay attention to my PRIMARY question.

My PRIMARY question was how to dynamically modify the NODE TITLE text of any node nonprogrammatically - at will somehow.

I want to be able to COMPLETELY replace the ENTIRE title text of any node dynamically, not just end up with another string with the HARDCODED 'blog' appended to it.

Your super hack non solution would NOT be provide a solution to the question I asked about.

Furthermore, your hack/non-solution asks me to transform my ENGLISH into a PSUEDO language that would not match the LANGUAGE selector name in the localization interface, confusing anyone else working with me to produce content.

blog.module - excerpt WITH HARDCODED HACK CODE

/* line 127 */
if ($account->uid) {
drupal_set_title($title = t("%name's blog", array('%name' => $account->name)));
[...]

/* drupal with a better design would have all blogs/books/forums (and the parent psuedo containers') titles in the admin UI with a title field stored in the database */

if ($node->uid)
{
drupal_set_title($title = $node->title);
}

a) Unless you can PAY ATTENTION and answer my ACTUAL - PRIMARY question,
(1) Take your HACK non-solutions elsewhere;
b) especially when you stated 'I've never done this';
c) your solution doesn't work because exporting the en-US little output (see actual result below) and it does address my original PRIMARY requirements;
e) Don't LECTURE me about paying attention when you have not; and
f) Chill out dude..

p.s. - even if your personal site does look nice -
- TRANSLATE IT INTO AN ENGLISH VERSION.
- http://pctips.ustilago.org/
- and put a translate button on your site for the english version.
- (example of site with german/english versions www.creamware.com )

p.p.s - blog.module has MANY more HARDCODED logic problems in it that should instead be modifiable through the drupal admin user interface. Here is yet another example:

There isn't any way to place the 'Post new blog entry' option BELOW the blog entries because it is HARDCODED into the blog.module code as follows:

function blog_page_user($uid) {
global $user;

$account = user_load(array((is_numeric($uid) ? 'uid' : 'name') => $uid, 'status' => 1));

if ($account->uid) {
/* HARCODED "%name's blog" - string logic */
drupal_set_title($title = t("%name's blog", array('%name' => $account->name)));

/* HARCODED position of 'Post new blog entry' option before the blog nodes */
/* if I want it below I have to hack the DRUPAL CORE CODE !!!!!!! */

if (($account->uid == $user->uid) && user_access('edit own blog')) {
$output = '

  • '. l(t('Post new blog entry.'), "node/add/blog") .'
  • ';
    }
    else if ($account->uid == $user->uid) {
    $output = '

  • '. t('You are not allowed to post a new blog entry.') .'
  • ';
    }

    if ($output) {
    $output = '

      '. $output .'

    ';
    }
    else {
    $output = '';
    }

    $result = pager_query(db_rewrite_sql("SELECT n.nid, n.sticky, n.created FROM {node} n WHERE type = 'blog' AND n.uid = %d AND n.status = 1 ORDER BY n.sticky DESC, n.created DESC"), variable_get('default_nodes_main', 10), 0, NULL, $account->uid);
    while ($node = db_fetch_object($result)) {
    $output .= node_view(node_load(array('nid' => $node->nid)), 1);
    }
    $output .= theme('pager', NULL, variable_get('default_nodes_main', 10));
    $output .= theme('xml_icon', url("blog/$account->uid/feed"));

    drupal_add_link(array('rel' => 'alternate',
    'type' => 'application/rss+xml',
    'title' => t('RSS - %title', array('%title' => $title)),
    'href' => url("blog/$account->uid/feed")));
    print theme('page', $output);
    }
    else {
    drupal_not_found();
    }

    ---------------------

    Below the COMPLETE contents of exporting the default en-US 'translation'

    --------------------

    # LANGUAGE translation of PROJECT
    # Copyright (c) YEAR NAME
    #
    msgid ""
    msgstr ""
    "Project-Id-Version: PROJECT VERSION\n"
    "POT-Creation-Date: 2006-01-31 04:17-0800\n"
    "PO-Revision-Date: YYYY-mm-DD HH:MM+ZZZZ\n"
    "Last-Translator: NAME \n"
    "Language-Team: LANGUAGE \n"
    "MIME-Version: 1.0\n"
    "Content-Type: text/plain; charset=utf-8\n"
    "Content-Transfer-Encoding: 8bit\n"
    "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"

    spritefully yours
    Technical assistance provided to the Drupal community on my own time ...
    Thank yous appreciated ...

    sprite’s picture

    ( slightly off topic - but heck - I did ask the original question )

    The layout of page/node elements could be implemented in a way similar to the way blocks are place inside their sidebar containers.

    Each component of a page/node e.g.:

    .main-content.node.title
    .main-content.node.info
    .main-content.node.links
    .main-content.node.terms
    .main-content.node.content
    ( and so on )

    Could be in a DIV container that is positionable relative to the parent DIV container such as:

    .main-content.node
    or
    .main-content.sticky
    or
    (whatever DIV container)

    using CSS positioning.

    The user interface could be similar to the present [-10 through 10] priority list

    OR

    better yet - the user interface could directly take CSS positioning properties to define the relationship between each of the components of the node. The CSS position values would be stored in the drupal database instead of being HARDCODED in the internal modules php code !!!!!!!!!!!!!!!!!

    THE RESULT

    total user control over positioning of the components of any/every node.

    Combined with storage of the node TITLES and other text like that in the drupal database, things could get truly super cool.

    - similar design/architecture solution apply throughout the drupal product
    - the overall scheme should store EVERYTHING in the database.
    - the relationships between database elements and their CSS selector names and IDs should transparent to the system and theme creators, and content developers alike.
    - Drupal is a great start - but there is enormous room for architectural and design improvement.

    [spritefully yours]

    spritefully yours
    Technical assistance provided to the Drupal community on my own time ...
    Thank yous appreciated ...

    heine’s picture

    Fair enough. It seems we have a different definition of what a 'hard coded string' is.

    Your initial post contained a number of questions, none exactly labelled 'primary'. In this forum, people try to reply to questions they have answers (or pointers) to. For example: how to change the %name's blog output in question in a non programmatic way.

    To go back to your question:

    Is there a non programmatic way to override the NODE TITLE text
    - on a per node or
    - per node type bases
    such as: - for example - the BLOG TITLE text when a blog is displayed, where the default would be: blog
    that I want to replace with an arbitrary text string instead?
    A similar example occurs when displaying the root blogs page at the URL 'blog' where the title begins simply 'blogs'

    (emphasis added)

    Usually, the node title is the title that you give to for example a story, blog post or page. Only a number of pages have a title that's different. Those pages are usually overview pages; eg. those displaying a certain taxonomy term (title = term), the 'root' blog page (title = blogs) or a user's blog (title = user_name's blog).

    Now, if you want to change the node title dynamically you can't escape a little programming (eg theming). Overriding it on a 'node type' basis is easier. Your statement regarding: $title = t("%name's blog", array('%name' => $account->name)) and the 'non-solution' confuses me a little:

    [...] not just end up with another string with the HARDCODED 'blog' appended to it.

    All(most all) interface elements in Drupal can be changed by using the locale module. In fact, you can change this line to almost anything using locale. If you want the username to show, you need to use %name in the localised string, but it's certainly not required. If you use locale to enter the string %name's musings you effectively changed the normal Sprite's blog title to Sprite's musings. There's no need for the 'blog' to be in there.

    1) Take your HACK non-solutions elsewhere;
    b) especially when you stated 'I've never done this';
    c) your solution doesn't work because exporting the en-US little output (see actual result below) [snip my 'primary' requirements etc.]

    Let's go on to the nature of the solution. Is it a hack? Or is it simply leveraging the powerful localisation features of Drupal? Your English doesn't have to be transformed into a 'PSEUDO' language. Drupal uses the two-letter code en by default. According to RFC1766 it's allowed to use subtag, for example: en-US or en-GB. Secondary subtags are also allowed: en-US-local or en-US-sitename. The language name can also be English (Drupals default is English (provided by Drupal)). Simply disable the English (provided by Drupal) and you have your adapted interface.

    Some advantages of using locale, instead of adapting strings directly in the source are:

    1. Accessible via Administration interface
    2. Survives an update
    3. Works with translations
    4. Patches near the string will still apply

    A hack? Very sensible actually; it featured in the September 2005 Drupal newsletter. See also the relevant handbook page.

    I gave you a pointer so you could find a new angle to your problem. A little experimenting or searching goes a long way.

    I've tried the 'HACK non-solution' on an in-development website of mine (http://realmeds.org/) and it worked fine. I've no idea why it didn't work for you, but it must have been frustrating. Turns out that there's actually an easier way; simply create a new language and you're more or less done: read the instructions in the handbook to see the details.

    Enjoy Drupal.

    Heine

    PS: post code between code-tags or php-tags. That way, the code won't be mangled beyond recognition by the inputfilters. Using php-tags has the additional advantage of syntax-coloring.

    Regarding p.p.s. : it's certainly unfortunate that 'Post new blog entry' (although changeable), isn't themeable.

    Regarding p.s. : I'm not going to translate my site into English; my primary audience is Dutch. Selected articles yes, entire content/interface; no. But thank you for the compliment!

    (edit fixed spelling, node type, added title =)
    --
    Tips for posting to the forums.
    When your problem is solved, please post a follow-up to the thread you started.