Click here to register.
      
Sprechen Sie WebGUI? Parlez vous WebGUI? Se habla WebGUI? Spreekt u WebGUI?

Do you speak WebGUI? Please help us translate WebGUI into your language.



     Discuss > Etcetera Goto page «Previous Page   1 2    Next Page»

Return of the If macro?

User aaronp
Date 9/3/2006 4:59 am
Views 3473
Rating 1    Rate [
|
]
Previous · Next
User Message
aaronp

The If(); macro was removed as of v6.8.4.  I found this feature beyond useful for many of the projects I work with, and in some cases, is the only solution to many problems.  I had been able to use If.pm all the way through v6.8.10 with minor tweaks, but there is no way to use it with v7.0.x without a major overhaul.

Will the If(); macro ever be brought back from the dead?  I gather that it was difficult to support, but could it maybe be brought back as a contrib or unsupported option?  Something that "is likely to work", but is unsupported by PB (i.e. your mileage may vary).  This is the only issue that is keeping me from upgrading to v7.0.x.  Thanks.

--- (Edited on 9/ 3/2006 4:59 am [GMT-0500] by aaronp) ---



Back to Top
Rate [
|
]
 
 
crythias

The Temple::Expr thing seems to be what's in its place. Since If could be used to evaluate *any* perl code, I believe that was why it was removed. 

 --
Maintainer of an unofficial WebGUI FAQ Please contribute questions or answers!
When asking questions on this forum, please indicate (at least) which version of WebGUI you are using. Optional, but sometimes helpful, are your Operating System name and version, PERL version, and Apache version. The little icons next to my picture indicate my IM status. Yes, you are welcome to IM me. I am not an employee of Plain Black. My offers of assistance are subject to the general disclaimer of this discussion board that my answer may be completely wrong. Have a great day!

www.gwy.org U2U crythias on #webgui on irc.freenode.net

--- (Edited on 9/ 3/2006 3:51 pm [GMT-0400] by crythias) ---



Back to Top
Rate [
|
]
 
 
colink
Try using HTML::Template::Expr and it will get you an if statement.  You'll need to change your templates to use it instead of HTML::Template (the default).

--- (Edited on 9/ 3/2006 7:09 pm [GMT-0500] by colink) ---



Back to Top
Rate [
|
]
 
 
aaronp

This was very helpful.  I wasn't aware that the alternate parser offered additonal funtionality.  Although HTML::Template::Expr seems to offer excellent boolean comparisons, I'm still struggling to find how I can do regular expression matching.  For example:

<tmpl_if expr="'^Env(HTTP_USER_AGENT);' =~ / MSIE /i>Go to the back of the class!</tmpl_if>

 ...doesn't work.  Any ideas?  Thanks!

--- (Edited on 9/ 4/2006 1:11 am [GMT-0500] by aaronp) ---



Back to Top
Rate [
|
]
 
 
colink

This is just my two cents, so take it with a grain of salt ;)

Templates are a bad way to do this, because your typical template writer is not a coder.  They're a graphic designer, specializing in layout with some small level of coding (loops, variables, macros).  I would build small, special purpose macros for doing browser identification or any other small tasks.

This keeps logic out of your template and has the added advantage of allowing you to build tests for the logic, since it's code.  If your logic fails due to some new browser, its way easier to test it in code space (where you set the environment variables to values) rather than in browser space (finding a browser that lets you spoof the USER_AGENT and then manually entering all of the browsers in one at a time). 

Doing it as macros will also enable you to release your macros to the community, where you get fame, acclaim and karma.

Of course, you could also do it in javascript if you prefer.

--- (Edited on 9/ 4/2006 11:23 am [GMT-0500] by colink) ---



Back to Top
Rate [
|
]
 
 
colink

I just went and read the HTML::Template::Expr docs, and there's one other way that it can help you.

H::T::E lets you define your own template functions.   This would require building a new custom template plug-in to WebGUI that would embed your functions in it:

<tmpl_if EXPR="isa_MSIE_browser()">

In addition to HTML::Template::Expr, you can plug in _any_ other templating module, including Mason, Template::Toolkit or even PHP. WebGUI ships with a plug-in for Template::Toolkit.

--- (Edited on 9/ 4/2006 11:30 am [GMT-0500] by colink) ---



Back to Top
Rate [
|
]
 
 
aaronp

I agree (to an extent), but simple regex matching shouldn't be beyond most people who have already worked up the nerve to use WebGUI in the first place.  I think it's prohibitive to have to contact a programmer if you just want to display different text based on the time of day, the users browser type, or remote IP address.

I'm not advocating adding a C-like syntax here, just simple regex matching.  If tmpl_if simply supported this new feature, I'd be very happy.  I suppose I should be talking to the HTML::Template::Expr folks about this.

--- (Edited on 9/ 6/2006 1:03 pm [GMT-0500] by aaronp) ---



Back to Top
Rate [
|
]
 
 
mpdaggett

How do you change your templates to use HTML::Template::Expr?

I am unable to get it working.

--- (Edited on 9/ 6/2006 4:11 pm [GMT-0500] by mpdaggett) ---



Back to Top
Rate [
|
]
 
 
colink

0) Install HTML::Template::Expr from CPAN 

1) Enable HTML::Template::Expr in your webgui config file in the templateParsers section

2)  restart Apache

3) When you create or edit a template, select HTML::Template::Expr as the template parser to use 

--- (Edited on 9/ 6/2006 5:01 pm [GMT-0500] by colink) ---



Back to Top
Rate [
|
]
 
 
xdanger

If I'm not wrong this little modification should do it. here

No warranty, haven't tested it my self, but I'm a big fan of the If-macro ;) (translation: I would have done this sooner or later) 

--- (Edited on 2006-09-05 15:19 [GMT+0300] by xdanger) ---



Back to Top
Rate [
|
]
 
 
     Discuss > Etcetera Goto page «Previous Page   1 2    Next Page»



Recent Discussions Color Key

Design:

Development:

Et Cetera:

Install/Upgrade:  

Smoketest:

Template Group:


Re: Navigation links by techwriter - Fri @ 03:23pm

Re: Best way to make files available to webgui comunity by bernd - Fri @ 02:50pm

Re: User event history by knowmad - Fri @ 02:02pm

Re: Best way to make files available to webgui comunity by lctn2 - Fri @ 01:55pm

Re: Strategic Roadmap by JT - Fri @ 01:55pm

Re: Navigation links by rogier - Fri @ 01:55pm

Re: 2009 Presidents Meeting by JT - Fri @ 01:10pm

Re: navigation new window by rogier - Fri @ 01:03pm

Re: navigation new window by rogier - Fri @ 12:53pm

Re: WUC 2009 by JT - Fri @ 12:50pm

Re: Best way to make files available to webgui comunity by preaction - Fri @ 12:35pm

Re: Pagination markup by rogier - Fri @ 12:35pm

Re: Best way to make files available to webgui comunity by kristi - Fri @ 12:29pm

Debian and Ubuntu Packaging Status by jmarsden - Fri @ 12:12pm