Jump to content

Choose which parts of a file to include using switch?


poleposters

Recommended Posts

Hi,

 

I'm writing a script which depending on certain factors includes the appropriate template.

 

Rather than have each template as a seperate file I thought it would be easier to combine all the templates into a single file and then weed out the appropriate section to include using a switch statement.

 

ie

include("email_template.php?template=3);

would include only what was found in case 3 of the switch statement.

 

However, this doesn't seem to be working.

 

I get the following error

 

An error occurred in script 'C:\xampp\htdocs\mailroom.php' on line 145:

include(email_template.php?template=3) [function.include]: failed to open stream: No error

 

Is what I'm trying to do possible using this method? Can somebody suggest a different apporach?

 

Thanks in advance.

It is possible, but not with that method. You would have to set the variable prior to calling it. IE:

 

$template = 3;
include('template.php');

 

If you are using GET data, you could also do this:

$_GET['template'] = 3;
include('template.php');

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.