You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Andre Breiler <an...@rd.bbc.co.uk> on 2004/03/11 15:46:58 UTC

functions in SSI

Hi,

I wonder what your opinion is on having functions in addition to variables
in SSIs.
An example would be <--#set var="blah" value="random($min,$max)" --> .

My idea is to make ap_ssi_parse_string aware of functions and call a
function which does the SSI function parsing/calling.
In addition I'd export a function so that other modules can register
SSI functions as well.

Andre
-- 
Andre' Breiler              | Tel: +44 (0) 1628 407777
BBC Internet Services       | URL: http://support.bbc.co.uk
Maiden House, Vanwell Road  |
Maidenhead, SL6 4UB         | Mail me if possible. And use a Subject line.


Re: functions in SSI

Posted by André Malo <nd...@perlig.de>.
* Patrick Welche <pr...@newn.cam.ac.uk> wrote:

> .. and if we are talking wish-list, I have often wanted to do something
> like
> <!--#set var="dir" value="/long/and/complicated/directory/path/name/" -->
> <!--#include file="<!--#echo var="dir" -->filename" -->
> 
> or somesuch less contrived, but nested example.

This example is bad since 'include file' takes only paths below the current
one.
However, you should already be able to use

<!--#include file="${dir}filename" -->

(See mod_include documentation)

nd

Re: functions in SSI

Posted by Patrick Welche <pr...@newn.cam.ac.uk>.
On Fri, Mar 12, 2004 at 01:53:20PM -0500, Mike Friedman wrote:
> 
> On Mar 12, 2004, at 1:40 PM, Patrick Welche wrote:
> 
> >.. and if we are talking wish-list, I have often wanted to do something
> >like
> ><!--#set var="dir" value="/long/and/complicated/directory/path/name/" 
> >-->
> ><!--#include file="<!--#echo var="dir" -->filename" -->
> >
> 
> How about <!--#include virtual="$dir/filename.html" -->
> 
> :)

OK, you can pick yourself of the floor and stop laughing :-)

Given the above, there can't be a contrived example - must revisit the
problem..

Thanks,

Patrick

Re: functions in SSI

Posted by Mike Friedman <fr...@friedo.com>.
On Mar 12, 2004, at 1:40 PM, Patrick Welche wrote:

> .. and if we are talking wish-list, I have often wanted to do something
> like
> <!--#set var="dir" value="/long/and/complicated/directory/path/name/" 
> -->
> <!--#include file="<!--#echo var="dir" -->filename" -->
>

How about <!--#include virtual="$dir/filename.html" -->

:)


BTW, while we're discussing mod_include, you folks might be interested 
in a patch I posted a while ago for sticking query string values in 
mod_include vars. I don't know if it's still current to the newer 
mod_include code, but here it is if anyone's still interested.

http://marc.theaimsgroup.com/?l=apache-httpd-dev&m=106352327003791&w=2


Re: functions in SSI

Posted by Patrick Welche <pr...@newn.cam.ac.uk>.
.. and if we are talking wish-list, I have often wanted to do something
like
<!--#set var="dir" value="/long/and/complicated/directory/path/name/" -->
<!--#include file="<!--#echo var="dir" -->filename" -->

or somesuch less contrived, but nested example.

Cheers,

Patrick

Re: functions in SSI

Posted by Brian Pane <br...@apache.org>.
On Mar 12, 2004, at 11:01 AM, Andre Breiler wrote:

> Hi,
>
> On Fri, 12 Mar 2004, Brian Pane wrote:
>
>> That definitely sounds useful.  I think you can get the same effect,
>> though, by using the existing 2.0/2.1 mod_include hook to add new
>> directives... something like this:
>>      <!--#set_random var="blah" min="$min" max="$max" -->
>>
>> That's not quite as syntactically elegant, but it has the advantage
>> of not requiring any new parsing code.  What do you think?
>
> Yes that was one of my other ideas as well :)
> The reason I asked for the below first was that it makes it a little
> more easier for the html author and that other modules which might use
> ap_ssi_parse_string won't get the benefit of functions.
> In addition I was thinking about a function "eval" feeding the content
> of a variable into ap_ssi_parse_string again.
> The last minor thought was that I wouldn't have to replicate most of
> the #set code again.
>
> The third idea (which we use atm.) is:
> <!--#set var="blah" function="random" value="$min" value="$max">
> .
> I really don't like that one as it means that I have to modify #set
> without getting a benefit.
>
> What speaks for your idea is that here wouldn't be any code changes to
> existing code needed and that it prevent dump users even getting near
> recursions.
>
> Let me know what you think if I should go for the more flexible (imho) 
> or
> the safer way.

I like the "<!--#set_random_var ..." approach best because it doesn't
require new parsing code, and mod_include's parser is very complex
already.  On the other hand, adding function support within
ap_ssi_parse_string would only require very localized changes, so
it would be low-risk.  I think either approach would be reasonably
safe.

Brian


Re: functions in SSI

Posted by Andre Breiler <an...@rd.bbc.co.uk>.
Hi,

On Fri, 12 Mar 2004, Brian Pane wrote:

> That definitely sounds useful.  I think you can get the same effect,
> though, by using the existing 2.0/2.1 mod_include hook to add new
> directives... something like this:
>      <!--#set_random var="blah" min="$min" max="$max" -->
> 
> That's not quite as syntactically elegant, but it has the advantage
> of not requiring any new parsing code.  What do you think?

Yes that was one of my other ideas as well :)
The reason I asked for the below first was that it makes it a little
more easier for the html author and that other modules which might use
ap_ssi_parse_string won't get the benefit of functions.
In addition I was thinking about a function "eval" feeding the content
of a variable into ap_ssi_parse_string again.
The last minor thought was that I wouldn't have to replicate most of
the #set code again.

The third idea (which we use atm.) is:
<!--#set var="blah" function="random" value="$min" value="$max">
.
I really don't like that one as it means that I have to modify #set
without getting a benefit.

What speaks for your idea is that here wouldn't be any code changes to
existing code needed and that it prevent dump users even getting near
recursions.

Let me know what you think if I should go for the more flexible (imho) or
the safer way.

Happy weekend,
 Andre'

> Brian
> 
> On Mar 11, 2004, at 6:46 AM, Andre Breiler wrote:
> 
> > Hi,
> >
> > I wonder what your opinion is on having functions in addition to 
> > variables
> > in SSIs.
> > An example would be <--#set var="blah" value="random($min,$max)" --> .
> >
> > My idea is to make ap_ssi_parse_string aware of functions and call a
> > function which does the SSI function parsing/calling.
> > In addition I'd export a function so that other modules can register
> > SSI functions as well.
> >
> > Andre
> > -- 
> > Andre' Breiler              | Tel: +44 (0) 1628 407777
> > BBC Internet Services       | URL: http://support.bbc.co.uk
> > Maiden House, Vanwell Road  |
> > Maidenhead, SL6 4UB         | Mail me if possible. And use a Subject 
> > line.
> >
> 

-- 
Andre' Breiler              | Tel: +44 (0) 1628 407777
BBC Internet Services       | URL: http://support.bbc.co.uk
Maiden House, Vanwell Road  |
Maidenhead, SL6 4UB         | Mail me if possible. And use a Subject line.


Re: functions in SSI

Posted by Brian Pane <br...@apache.org>.
That definitely sounds useful.  I think you can get the same effect,
though, by using the existing 2.0/2.1 mod_include hook to add new
directives... something like this:
     <!--#set_random var="blah" min="$min" max="$max" -->

That's not quite as syntactically elegant, but it has the advantage
of not requiring any new parsing code.  What do you think?

Brian

On Mar 11, 2004, at 6:46 AM, Andre Breiler wrote:

> Hi,
>
> I wonder what your opinion is on having functions in addition to 
> variables
> in SSIs.
> An example would be <--#set var="blah" value="random($min,$max)" --> .
>
> My idea is to make ap_ssi_parse_string aware of functions and call a
> function which does the SSI function parsing/calling.
> In addition I'd export a function so that other modules can register
> SSI functions as well.
>
> Andre
> -- 
> Andre' Breiler              | Tel: +44 (0) 1628 407777
> BBC Internet Services       | URL: http://support.bbc.co.uk
> Maiden House, Vanwell Road  |
> Maidenhead, SL6 4UB         | Mail me if possible. And use a Subject 
> line.
>