Tanalis has asked for the wisdom of the Perl Monks concerning the following question:

Monks,

I'm trying to think my way through a fairly interesting problem at the minute, and seem to be getting nowhere fast, so I thought I'd post here, and see if anyone has any suggestions.

I'm currently in the middle of writing some code for a community website, using CGI::Application and HTML::Template to serve up semi-dynamic content.

We'd like to implement a forum/bulletin board type system as part of this, integrating this into the current page design and layout (for consistency reasons). Rather than hand-rolling a solution, it seemed to make sense to use mature code, and we decided to use YaBB to handle the forum's back-end code, as it seems to do everything we're likely to need.

Integrating this with the current website should, in my mind, be a fairly simple task - I've made modifications to allow YaBB to share a common user database, and to detect login cookies from the main website. So far so good.

However, what I originally thought would be the easiest part of the integration is the bit that's causing me the most trouble: how best to include output from the YaBB script in the existing HTML templating? With static content, I'd simply use HTML::Template's include function, but with dynamic content, where calls are going to return to the YaBB script, rather than the main page CGI, this obviously isn't going to work - you end up with only the YaBB data being returned.

I've thought of replacing the YaBB.cgi script with one of my own, that can call the main page CGI with the YaBB arguments, handing over to YaBB to generate the forum content, then integrating all this into the existing templating, but this seems a large job for what seems, at first glance, a simple task.

YaBB can itself handle templating, but I'm loathe to reimplement templates that already exist for the main site, especially as it'd remove the generated/dynamic content from the main CGI.

Does anyone have any suggestions about how best to include the results from an external CGI in either HTML::Template's templating, or in some other method?

I should probably point out that I'm not doing this to pass YaBB off as my own work - its copyrights and required links will remain on all pages generated by the YaBB engine. This is purely for asthetic and consistency reasons across the site.

Any suggestions or comments would be welcomed.

Thanks in advance for your help.
-- Foxcub
A friend is someone who can see straight through you, yet still enjoy the view. (Anon)

  • Comment on Combining Results from Multiple CGIs into one HTML page

Replies are listed 'Best First'.
Re: Combining Results from Multiple CGIs into one HTML page
by rinceWind (Monsignor) on Apr 23, 2003 at 10:32 UTC
    There are several ways to achieve what you want to do. One way is to use the LWP mechanism to front-end the existing site. The module WWW::Mechanize will do everything you need for this, but you could alternatively hand-roll something with LWP::Simple or LWP::UserAgent.

    In terms of what to do with the page when you have obtained it from the other site, parse out the <BODY> tag, and include the raw HTML as it is, though you might want to do some lower level parsing to pull out information you need for your site. For this purpose, I recommend HTML::PullParser.

    Hope this helps,

    --rinceWind

      Why do you recommend HTML::PullParser? (inquiring minds want to know)


      MJD says you can't just make shit up and expect the computer to know what you mean, retardo!
      I run a Win32 PPM repository for perl 5.6x+5.8x. I take requests.
      ** The Third rule of perl club is a statement of fact: pod is sexy.

Re: Combining Results from Multiple CGIs into one HTML page
by Anonymous Monk on Apr 23, 2003 at 12:05 UTC

    Not a perl solution, but the easiest way would be to invoke the YaBB cgi from the url of an IFRAME/LAYER tag that you embed in your current layout. This could even have benefits in reducing load on your server by only redrawing the non-BB parts of the screen when the user does some thing to require it rather than each time they interact with the BB.

      does any browser show an iframe/layer tag .. i don't think so, but if wrong correct me.
Re: Combining Results from Multiple CGIs into one HTML page
by mattr (Curate) on Apr 23, 2003 at 12:41 UTC
    seems lwp might work, but are frames out of fashion?
Re: Combining Results from Multiple CGIs into one HTML page
by Coplan (Pilgrim) on Apr 23, 2003 at 16:24 UTC
    I had a similar situation on my old site. We had a bug tracking cgi program that we wanted to display with our menus and what-not all around it. It sounds like a very similar situation indeed.

    Where our situations differ is that I had my own template system that involved finding HTML REM tags, and replacing them with whatever was called for in the HTML tags. My template system would go through, look for these tags, and then run the appropriate subroutine. When it got to the tag for the bug tracking system, I just ran the cgi script. The advantage I had about our bug tracking system is that you could tell it not to print header/footer information (IE, the BODY, HTML, HEAD, etc tags). With that stuff gone, I could easily insert it where I wanted.

    You might be able to do a very similar thing with your application. You might be able to get all the output stored into a buffer, and you'd only have to print out the buffer when you needed to.

    Hope that helps steer you in the right direction.

    --Coplan

Re: Combining Results from Multiple CGIs into one HTML page
by playingwithbots (Novice) on Apr 23, 2003 at 20:57 UTC
    Not certan, but have you thought of these:

    - Why hot use your main template as the YABB template? Just use your main template and make the mods necessary to turn it into a YABB template. You'll want to add a lnk to get back to your main pages, but this should work

    - I think someone else mentioned it, but if your template uses frames, you can modify the YABB template and then the YABB output should be OK in the frame.

    - Can you use SSI exec to get YABB invoked as part of the page? Again, might need to change the YABB template to get rid of it headers.

    - Try the YABB forums. Those folks are YABB experts and have probably already faced this issue,