[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [cgiapp] Navigation Templates and Run Mode


* Brett Sanger <suppressed> [2005-10-19 15:04:42-0400]
[Highlighting runmode navigation in template]
> So I tried to move to include a Nav template.  For that to work,
> however, I need to make my run_mode visible to my template, which bugs
> me in some way.  The template shouldn't care.  But then, the template
> has to know the OTHER run modes to send you there, so I guess it's not a
> big deal, but it does bug me.

I don't see the big problem here. The template is supposed to know
the runmode, for then it can make decissions of where to send you
next. I might be missing something here ...
 
> The other remaining issue is that even in that case the navigation
> template is ugly.  A bunch of IF/ELSEs and bolding or alternate CSS ids.
> Not very readable, which means less maintainable.  

You only need one CSS id, to show the 'selected' runmode. And yes,
_somehow_ the template has to make a choice of what runmode is
current and therefore you'll have to throw some code in. This is,
however, the very reason templating systems exist!

Readable/maintainable, that's up to your preferred method and style
of coding I believe. Anyways, maintaining a few IF/ELSE statements
is still far easier than looping through 36 files to change the
navigation on every individual page ;-)

> I'm assuming this is an issue others have encountered before.  How do
> you handle navigation templates?

I usually end up using something like this:

runmode1.tt2
---------
[% INCLUDE header.tt2 %]
[% INCLUDE navigationmenu.tt2 %]
content for runmode1
[% INCLUDE footer.tt2 %]

runmode2.tt2
---------
[% INCLUDE header.tt2 %]
[% INCLUDE navigationmenu.tt2 %]
content for runmode2
[% INCLUDE footer.tt2 %]

etc.

Header and Footer files are up to you. It's the basic opening and
closing tags that are relatively common throughout your pages
(<html>, <head>, <body>, etc.).

In navigationmenu.tt2, I'd hack something like this:
<ul id="navigation">
   <li[% (rm == 'rm1') ? ' id="current"' : '' %]>
	<a href="/app/rm1">Runmode 1</a>
   </li>
   <li[% (rm == 'rm2') ? ' id="current"' : '' %]>
	<a href="/app/rm2">Runmode 2</a>
   </li>
   <li[% (rm == 'rm3') ? ' id="current"' : '' %]>
	<a href="/app/rm3">Runmode 3</a>
   </li>
</ul>

If you want to specify a default class otherwise, you could go for
something like:

   <li class="[% (rm == 'rm1') ? 'selected' : 'notselected' %]">
	<a href="/app/rm1">Runmode 1</a>
   </li>

I myself find that quite readable.

Then all you need to do is to set 'rm' in your module. I usually put
it in cgiapp_prerun:

   $self->tt_params('rm', $self->get_current_runmode);

It's probably not the best way to handle it, but it works for me ;)

-- 
B10m
   'Google is Evil'
   -rw-rw-rw-  1 satan demons  0 Jun 06 06:06 google

---------------------------------------------------------------------
Web Archive:  http://www.mail-archive.com/suppressed/
              http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: suppressed
For additional commands, e-mail: suppressed


Mail converted by mhonarc 2.6.15
This archive provided courtesy of JSW4.NET, Internet Hosting Services for Small Business.