1

I am new in Drupal theming and I would like to control the "submitted by" part of a node. I want to remove the name of the author and stylize the created_date of the node. The problem is that I also echo some greek characters that show up in weird symbols in my site. I tried changing the encoding to utf-8 but it won't work. I am not even sure what the original encoding of node.tpl.php is. How would I go inserting my own custom text inside node.tpl.php and printing it correctly?

<?php if ($display_submitted): ?>
  <footer class="submitted"><?php $posted="Δημοσιεύτηκε στις "; echo mb_convert_encoding($posted, "UTF-8", "Windows-1252") . date( "d F, Y",$node->created); ?></footer>
<?php endif; ?>

The code above returns:

Äçìïóéåýôçêå óôéò 12 January, 2012

I also tried utf8_encode function but that was a long shot since it converts ISO-8859-1 strings to UTF-8.

2

If the file is correctly saved as UTF-8, it should correctly handle Unicode characters. So far, I have had a problem with the saved file just because the editor I was using added the BOM ("Byte Order Mark") used to identify the encoding of the file, but the error was a different one.

Generally speaking, the Drupal way to have a translatable site is to use t() in your code, which requires the English string that will then be translated to the language set as default, basing on the translation provided to the Language module.

The code should be rather be similar to the following one:

<?php if ($display_submitted): ?>
  <footer class="submitted"><?php t('Submitted by !username on !datetime', array('!username' => $name, '!datetime' => $date)););</footer>
<?php endif; ?>

The alternative is implementing hook_preprocess_node(&$variables) (template_preprocess_page() in a theme), and initialize the variable $variables['submitted'] to the string you want to appear ("Submitted by !username on !datetime" in the code I shown before).

  • When opening node.tpl.php with notepad++, under the encoding menu the Encode in ANSI is enabled. Not sure if this could be causing the problem since I tried enconding the string from ANSI to utf-8 without luck. But the hook_preprocess solution seems to be a good one. I need to learn how to do it and come back with the results. Thanks for pointing me towards the right direction. – Perisdr Jan 12 '12 at 10:19
  • I tried adding a preprocess function biztech_alpha_preprocess_node(&$vars) { $variables['submitted'] = t('Submitted by !datetime', array('!datetime' => $variables['created'])); } But i got the same unreadable symbols. Makes sense since you said I need to provide the english string to be translated by the Language module. I guess my best shot is to go and manually add a unique english string through locale and provide its greek translation. So much trouble for changing one line.. – Perisdr Jan 12 '12 at 11:39
0

You might want to try the submitted_by module. Since all entered strings go through the Drupal system you shouldn't need to use any encoding functions in your template.

  • I was looking for a way to do this without a module but I will definitely give it a try to see if it meets my needs. Thanks. – Perisdr Jan 12 '12 at 10:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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