Question

so I have this code:

  $template_file = 'template.tpl.php';
  ob_start();                      // Start output buffering
  include "./$template_file";      // Include the template file
  $contents = ob_get_contents();   // Get the contents of the buffer
  ob_end_clean();                  // End buffering and discard
  return  $contents;

this is what template.tpl.php looks like:

<?=translate_string('A message to display to user')?>

however when I inspect the content of $contents, instead of having it display 'A message to display to user' it instead displays <?=translate_string('A message to display to user')?> ... ie. it displays the PHP code in entirety instead of executing the PHP code and simply return the output of the executed code...

Any idea on what could possibly cause this?

I'm using Drupal 6

EDIT

looks like short_open_tag setting is On...any other possibilities?

also it would be great if I can still use <?= notation without making it <?php etc... since it's used quite prevalently

Further Update

looks like jszobody no longer have further contribution, if anyone else knows what could possibly cause this other than the short_open_tag setting, feel free to answer

thx to jszobody for the short_open_tag contribution

Was it helpful?

Solution

You are using PHP short tags in your template code. If those are not enabled on your server, it's not parsed by PHP, and instead treated as plain text.

See here: http://www.php.net/manual/en/ini.core.php#ini.short-open-tag

I'd change your template to this:

<?php echo translate_string('A message to display to user'); ?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top