Click here to register.
      
irc://irc.freenode.net#webgui

iPhoneGuy: WebGUI is a pile of crap.
rizen: If WebGUI is such a pile of crap, why do you use it?
iPhoneGuy: Because it's the best pile of crap out there.

If this is what people who hate us are saying, imagine what people who love us will say. Come join us on IRC.


     Etcetera > if/unless/then/else regex in templates

if/unless/then/else regex in templates

User aaronp55426
Date 4/29/2008 10:05 am
Views 1117
Rating 0    Rate [
|
]
Previous · Next
User Message
aaronp55426

I'd like to do regex string comparisons in templates in WG v7.4.34.  I've looked at both HTML::Template and HTML::Template::Expr, but I can't find anything that works.  I want to do this:

        <tmpl_if expr="currentPage.url=~/about/">

           YES!

        </tmpl_if>

 

I think HTML::Template::Pro may be an option, but it doesn't seem to be supported in WebGUI.  Am I missing something, or is simple string regex matching not possible?  Thanks.

--- (Edited on 4/29/2008 10:05 am [GMT-0500] by aaronp55426) ---



Back to Top
Rate [
|
]
 
 
JT

Step up to Template Toolkit.

--- (Edited on April 29, 2008 11:08 am [GMT-0500] by JT) ---



Back to Top
Rate [
|
]
 
 
aaronp55426

Thanks for the input.  I've installed Tempolate Toolkit.  The problem is that I'm building a navigation template, and it would take a while to rewrite the existing templates to support the new syntax.  Are there are prewritten Template Toolkit vertical navigation templates for WebGUI v7.4 available for download?  It seems like a long shot, but I though I'd ask.

--- (Edited on 4/29/2008 12:45 pm [GMT-0500] by aaronp55426) ---



Back to Top
Rate [
|
]
 
 
aaronp55426

I'm giving HTML::Template::Expr one last try:

   <tmpl_if expr="currentPage_url =~ /about/">

      YES!

   </tmpl_if>


... I get:

There is a syntax error in this template. Please correct.HTML::Template::Expr->new() : Error creating HTML::Template object : HTML::Template->new() : fatal error occured during filter call: HTML::Template::Expr : Unable to parse expression: (currentPage_url =~ /about/)

I think this should be working.  Could this be a simple syntax issue?  I would try Template Toolkit, but I don't want to write a navigation template from scratch using a new toolkit if I don't have to.   Thanks.

--- (Edited on 5/5/2008 5:39 am [GMT-0500] by aaronp55426) ---



Back to Top
Rate [
|
]
 
 
colink

It is a simple syntax issue.  HTML::Template::Expr does not allow regular expressions.

Read the docs:

http://search.cpan.org/~samtregar/HTML-Template-Expr-0.07/


If you want regular expressions, you need to use a different templating toolkit.

--- (Edited on 5/5/2008 10:09 am [GMT-0500] by colink) ---



Back to Top
Rate [
|
]
 
 
aaronp55426

You are right.  It does, however, support custom subroutines.  It seems kludgey, but this is the work around I ended up using:

In the Apache startup.pl script:

HTML::Template::Expr->register_function( ereg => sub { my $one = shift; my $two = shift; return 1 if $one =~ m/$two/; return 0; });

In the navigation template:

<tmpl_if expr="ereg(currentPage_url, 'about')">

    YES!

</tmpl_if>

I think I'll submit a feature request for WebGUI to support the HTML::Template::Pro template engine, which would be a more elegant solution.

--- (Edited on 5/5/2008 11:22 am [GMT-0500] by aaronp55426) ---



Back to Top
Rate [
|
]
 
 

Re: Config File Changes by pwrightson - Fri @ 04:07pm

Re: IRC Logs by koen - Fri @ 02:08pm

Re: IRC Logs by patspam - Fri @ 02:01pm

Re: IRC Logs by koen - Fri @ 01:42pm

Re: How do I find al my submitted RFE's? by bartjol - Fri @ 01:39pm

Re: IRC Logs by kristi - Fri @ 01:27pm

Re: LastModified question by perlDreamer - Fri @ 12:57pm

Re: How do I find al my submitted RFE's? by bartjol - Fri @ 12:11pm

How do I find al my submitted RFE's? by koen - Fri @ 11:23am

Re: IRC Logs by koen - Fri @ 11:20am

IRC Logs by martink - Fri @ 10:51am

Re: cleaning out the wiki by koen - Fri @ 10:44am

Re: shop in 7.5.21 by kristi - Fri @ 09:03am

shop in 7.5.21 by erikms - Fri @ 08:07am