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

if/unless/then/else regex in templates

User aaronp55426
Date 4/29/2008 10:05 am
Views 984
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 [
|
]
 
 
     Discuss > Etcetera




Re: Pagination and Navigation Menus. by colink - Thu @ 04:05pm

Re: Corrupt Asset Tree by mwille64 - Thu @ 02:12pm

Pagination and Navigation Menus. by eleger81 - Thu @ 11:52am

Re: Corrupt Asset Tree by preaction - Thu @ 11:44am

Corrupt Asset Tree by mwille64 - Thu @ 11:18am

Smoketest For nightly_2008-07-24 by Visitor - Thu @ 01:39am

Re: Hello! by crythias - Wed @ 01:13pm

Testing status, July 23, 2008 by colink - Wed @ 10:53am

Re: Paragarph issue in link lists by bernd - Wed @ 09:11am

Re: Dutch translation 7.5.17 done by Klaus - Wed @ 04:28am

Re: Hello! by Klaus - Wed @ 04:23am

Smoketest For nightly_2008-07-23 by Visitor - Wed @ 01:38am

Hello! by crythias - Tue @ 09:07pm

Re: Duplicate web site by techwriter - Tue @ 10:47am

Dutch translation 7.5.17 done by bartjol - Tue @ 09:13am