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.

Link to comment
Share on other sites

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');

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.