views:

14

answers:

2

hey. with the following code

<?php
if (qtrans_getLanguage() == "en") {
   echo <?php include( TEMPLATEPATH . '/slider_en.php' ); ?>;

}else{
      echo <?php include( TEMPLATEPATH . '/slider_de.php' ); ?>;
   }
?>

i'm trying to include a file, based on the chosen language of the website. guess my idea is right but i'm totaly wrong on the syntax of using include in an echo..

can someone please oint me in the right direction?

many thanks,

tobi.

+1  A: 

You are already in PHP mode, so you don't need to re-open the PHP tags (<?php). Remove them, and it should work. You don't even need the echo, since PHP drops out of PHP mode and back in HTML mode when it includes a file.

<?php
if (qtrans_getLanguage() == "en") {
   include( TEMPLATEPATH . '/slider_en.php' );

} else {
   include( TEMPLATEPATH . '/slider_de.php' );
}
?>
Jan Fabry
i think php's include just returns a boolean you don't have to echo the content.
Tim
sweet. you guys are fast as hell answering questions! i fixed it myself, but with much uglier(?) code than you did.. <code><?php if (qtrans_getLanguage() == "en") { ?> <?php include( TEMPLATEPATH . '/slider_en.php' ); ?> <?php }else { ?> <?php include( TEMPLATEPATH . '/slider_de.php' ); ?> <?php }?></code>thanks for the help, much appreciated.tobi.
tobi
@Tim: Indeed, I didn't check my example in the first edit, but I corrected it. @tobi: Your solution also works, but if you follow an ending tag with an opening tag (`?><?php`), you might as well just drop both.
Jan Fabry
A: 

You can't echo an include. Try just including the file, otherwise you can try the get_file_contents function, which returns the file as a string.

echo get_file_contents( TEMPLATEPATH . '/slider_de.php');

More info on get_file_contents: http://php.net/manual/en/function.file-get-contents.php

Chris Schmitz
file_get_contents
Jhong
Yup, my bad....
Chris Schmitz