logo
Apache Lounge
Webmasters

 


About

Forum Index Downloads Search Register Log in  RSS Apache Lounge
 



Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Apache Lounge is not sponsored.

Your donations will help to keep this site alive and well, and continuing building binaries.



Including different files using SSI?

 
Post new topic   Reply to topic    Apache Forum Index -> Coding & Scripting Corner



View previous topic :: View next topic  
Author Message
jensdahlin



Joined: 18 Dec 2007
Posts: 2

PostPosted: Tue 18 Dec '07 16:22    Post subject: Including different files using SSI? Reply with quote

I want to include different files based on a parameter sent via the URL.

If the URL is [...]program.shtml?param=value

I want to include value.inc
<!--#include virtual="value.inc" -->

However if the URL is [...]program.shtml?param=anothervalue

I want to include value2.inc
<!--#include virtual="value2.inc" -->

I can't seem to find a solution to this problem - at least not without using perl or something like that and I would like to make this as easy as possible. Any hints?

Best regards
Jens
Back to top
glsmith
Moderator


Joined: 16 Oct 2007
Posts: 2123
Location: Sun Diego, USA

PostPosted: Tue 18 Dec '07 22:31    Post subject: Reply with quote

Well, being that it doesn't read the query string I think you're out of luck. It does environment variables but all the SetEnvIf need would probably not be to your liking as well.
Back to top
tdonovan
Moderator


Joined: 17 Dec 2005
Posts: 610
Location: Milford, MA, USA

PostPosted: Wed 19 Dec '07 0:31    Post subject: Reply with quote

If you don't mind skipping the "param=" part of the query string, it becomes much easier.

Put this in your program.shtml page:
Code:
<!--#include virtual="${QUERY_STRING}.inc" -->
    If you request [...]program.shtml?value, program.shtml will include the file value.inc

    If you request [...]program.shtml?value2, program.shtml will include the file value2.inc

It might be a good idea to handle requests where there is no query string using default.inc.
For example:
Code:
<!--#if expr=${QUERY_STRING} -->
    <!--#set var="SELECTED_INCLUDE" value="${QUERY_STRING}" -->
<!--#else -->
    <!--#set var="SELECTED_INCLUDE" value="default" -->
<!--#endif -->
<!--#include virtual="${SELECTED_INCLUDE}.inc" -->

Hope this helps...

-tom-
Back to top
jensdahlin



Joined: 18 Dec 2007
Posts: 2

PostPosted: Wed 19 Dec '07 9:23    Post subject: Reply with quote

Thanks!

I experimented with your idea and found out a solution that suited me better:

<!--First I set a variable as the QUERY_STRING-value -->
<!--#set var="qs" value="$QUERY_STRING" -->

<!--Then I include file depending on the value of this variable.-->
<!-- I have an else-statement in the end - default value if no criteria matches -->
<!--#if expr="$qs='param=one'" -->
<!--#include virtual="/one.inc" -->
<!--#elif expr="$qs='param=two'"-->
<!--#include virtual="/two.inc" -->
<!--#elif expr="$qs='param=three'"-->
<!--#include virtual="/three.inc" -->
<!--#else -->
<!--#include virtual="/one.inc" -->
<!--#endif -->

Using some kind of regexp it might even be possible to break out the value-part of the url-parameter but this will have to do right now.

Once more: thanks!
Back to top


Post new topic   Reply to topic    Apache Forum Index -> Coding & Scripting Corner
Page 1 of 1