0

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.

2 Answers 2

1

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' );
}
?>
Sign up to request clarification or add additional context in comments.

3 Comments

i think php's include just returns a boolean you don't have to echo the content.
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.
@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.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.