[Fwd: RE: [ic] Using menu builder for breadcrumb trail nav]

David Radovanovic dave at whatsthebigidea.com
Thu Jul 29 12:27:45 EDT 2004


>-----Original Message-----
>From: interchange-users-bounces at icdevgroup.org
>[mailto:interchange-users-bounces at icdevgroup.org] On Behalf Of
>Paul Jordan
>Sent: Wednesday, July 28, 2004 2:48 PM
>To: interchange-users at icdevgroup.org
>Subject: RE: [ic] Using menu builder for breadcrumb trail nav
>
>Mike Heins [mike at perusion.com] wrote:
>> Quoting Paul Jordan (paul at gishnetwork.com):
>>> Mike Heins [mike at perusion.com] wrote:
>>>> Quoting David Radovanovic (david.radovanovic at verizon.net):
>>>>> Prerequisites:
>>>>>
>>>>> Interchange 5.00 running on FreeBSD 4.7 using MYSQL and
>Perl 5.8.2.
>>>>>
>>>>> After an exhaustive search in the user groups/mail/demos
>I haven't
>>>>> found an adequate solution to creating a simple "Breadcrumb"
navigation bar using IT tags. I tried creating a tree
>menu based on
>>>>> the contents of two tables that lies horizontally, though I only
want to show where the visitor is presently at within the site
structure and NOT the entire site menu. Is there a simple way to
accomplish this using Interchange's myriad of tags? BTW, can someone
please explain the "sel' Selector variables: "left" and "top".
>>>>
>>>> There is a [breadcrumbs] tag included in the latest CVS version of
IC, which is used in the new "standard" demo.
>>>>
>>>> Check out demo.icdevgroup.org to watch it in action.
>>>
>>>
>>> I was interested in seeing how it worked. Does it have desired behavior?
>>>
>>> 1.I go to home i get:
>>>
>>>  Welcome
>>>
>>> 2.I click on Hardware Category I get:
>>>
>>>  Welcome > Hardware
>>>
>>> 3.Expand Hardware and go to Nails I get:
>>>
>>>   Welcome > Hardware > Nails
>>>
>>> 4.Now, if I click on Hardware, either in the breadcrumb or
>the menu,
>>> I get:
>>>
>>>   Welcome > Nails > Hardware
>>>
>>> I would think that clicking on Hardware in #3 above, that "Nails"
would simply disappear.
>>>
>>> I want my money back! 8-). My curiosity was peaked by this new feature
so I just tried it out on the demo. I just wanted
>to post my
>>> initial findings.
>>
>> It does this intentionally -- the idea is that if you go to
>a category
>> you should see a hierarchical presentation.
>>
>> Not also that if you go to a flypage, it gets reset.
>
>
>I see, that does makes sense also.
>
>
>> If you want it to be different, change the tag. That is why we are open
source.... 8-)
>
>OK, I take that as a personal challenge ;) I will put this tag
>alteration on my personal 'pj_todo' list 8-)
>
>Paul
>



Great. Thanks. However, I tried using the breadcrumb.tag code (see #
BREADCRUMB # below) embedded into catalog.cfg (it is a local tag?) It just
prints out "[breadcrumbs reset-on-product=1]" on page. The rest of my
embedded UserTags seem to work fine, i.e. "caps" and "company_name" Any
thoughts?


---snip catalog.cfg -------



VariableDatabase site

#==========================================================================#

# Allow a template to drop in some beginning config.
include etc/before.cfg

#==========================================================================#

# Warn if any important modules or usertags are missing.

Require module Digest::MD5    "Need %s %s for better cache keys."
Require module Safe::Hole
Require module LWP::Simple

Require UserTag   email email_raw var loc table_editor button component

#==========================================================================#


UserTag caps   Routine   sub { return "\U at _" }
UserTag caps   HasEndTag

#==========================================================================#

 UserTag company_name Routine   sub { "Hudson Valley Dessert" }

#==========================================================================#
# BREADCRUMB #
#==========================================================================#

UserTag breadcrumbs Order number
UserTag breadcrumbs addAttr
UserTag breadcrumbs Routine <<EOR
sub {
	my ($number, $opt) = @_;

	use vars qw/$Tag $Scratch $CGI $Session $Variable/;
	my $only_last = $::Variable->{BREADCRUMB_ONLY_LAST} || 'ord/basket
login'; my $exclude   = $::Variable->{BREADCRUMB_EXCLUDE};
	my $max   = $number || $::Variable->{BREADCRUMB_MAX} || 6;

	my %exclude;
	my %only_last;

	my @exclude = split /[\s,\0]+/, $exclude;
	my @only_last = split /[\s,\0]+/, $only_last;
	@exclude{@exclude} = @exclude;
	@only_last{@only_last} = @only_last;

	my $curpage = $Global::Variable->{MV_PAGE};
	my $titles = $Scratch->{bc_titles} ||= {};

	my %special = (
		scan => sub {
			my $url = shift;
			my @items = split m{/}, $url;

			my $title;
			for(@items) {
				if(s/^se=//) {
					$title = $_;
				}
				elsif(s/^va=banner_text=//) {
					$title = $_;
				}
			}
			return ($title, $title);
		},
	);

	my $curhist   = $Session->{History}->[-1] || [];
	my $curparams = $curhist->[1] || {};

	my $keyname;

	my $curfull = $curhist->[0];
	$curfull =~ s/$Vend::Cfg->{HTMLsuffix}$//;
	$curfull =~ s{^/}{};
	my ($curaction,$curpath) = split m{/}, $curfull, 2;

	my $ptitle = $opt->{title} || $curparams->{short_title};
	$ptitle ||= $Scratch->{short_title};

	my $db;

	my @extra;

	if($special{$curaction} and ! $ptitle) {
		($ptitle, $keyname) = $special{$curaction}->($curpath);
	}
	elsif(
			$Vend::Flypart
				and
			$db = Vend::Data::product_code_exists_ref($Vend::Flypart)
		)
	{
		my $tab = $db->name();
		my $record = tag_data($tab, undef, $Vend::Flypart, { hash => 1});
$ptitle = $keyname = $record->{$Vend::Cfg->{DescriptionField}};

		if($record and $record->{prod_group}) {
			my @parms;
			push @parms, "fi=$tab";
			push @parms, "co=yes";
			push @parms, "st=db";
			push @parms, "sf=prod_group";
			push @parms, "se=$record->{prod_group}";
			push @parms, "op=eq";
			push @extra, {
				key => $record->{prod_group},
				title => $record->{prod_group},
				description => undef,
				url => $Tag->area({ search => join("\n", @parms) }),
			};
		}
		if($record and $record->{category}) {
			my @parms;
			push @parms, "fi=$tab";
			push @parms, "co=yes";
			push @parms, "st=db";
			if($record->{prod_group}) {
				push @parms, "sf=prod_group";
				push @parms, "se=$record->{prod_group}";
				push @parms, "op=eq";
			}
			push @parms, "sf=category";
			push @parms, "se=$record->{category}";
			push @parms, "op=eq";
			push @extra, {
				key => $record->{category},
				title => $record->{category},
				description => undef,
				url => $Tag->area({ search => join "\n", @parms }),
			};
		}
	}

	if(! $ptitle) {
		$ptitle = $Scratch->{page_title};
		$ptitle =~ s/(\s*\W+\s*)?$Variable->{COMPANY}(\s*\W+\s*)?//;
	}

	$ptitle =~ s/^\s+//;
	$ptitle =~ s/\s+$//;

	$keyname ||= $curpage;

	$titles->{$curpage} = $ptitle if $ptitle;

	my %exclude_param = qw(
		mv_pc 1
		bread_reset 1
	);

	if($Scratch->{bread_reset} || $CGI->{bread_reset}) {
		delete $Session->{breadcrumbs};
	}

	my $crumbs = $Session->{breadcrumbs} ||= [];
	my $crumb;

	if($opt->{reset_on_product} and @extra) {
#::logDebug("Resetting based on product");
		@$crumbs = ();
	}

	if(! $exclude{$curpage}) {
		my $form = '';
		for(grep !$exclude_param{$_}, keys %$curparams) {
		     $form .= "\n$_=";
		     $form .= join("\n$_=", split /\0/, $curparams->{$_});
		}
		$crumb = {
			key => $keyname,
			title => HTML::Entities::encode($ptitle),
			description => HTML::Entities::encode($Scratch->{page_description}),
url => $Tag->area({ href => $curfull, form => $form, secure =>
$CGI->{secure} }),
		};
	}

	push @$crumbs, @extra if @extra;
	push @$crumbs, $crumb if $crumb;

	my %seen;
	my @new = grep !$seen{$_->{key}}++, reverse @$crumbs;

	my $did_one;
	for(@new) {
		## Kill ones that only are allowed in last position
		if( $did_one and $only_last{$_->{key}}) {
			$_ = undef;
		}
		$did_one = 1;
	}

	if(@new > $max) {
		splice @new, $max;
	}

	@$crumbs = grep $_, reverse @new;

	my $tpl = $opt->{template} || <<EOF;
<a href="{url}"{description?} title="{description}"
class=breadlink>{title}</a>
EOF

	my @out;
	for(@$crumbs) {
		next unless ref($_) eq 'HASH' and $_->{url};
		my $link = tag_attr_list($tpl, $_);
#::logDebug("link=$link from:\ntpl=$tpl\ncrumb=" . ::uneval($_));
		push @out, $link;
	}

	$opt->{joiner} = ' > ' unless defined $opt->{joiner}; return join
$opt->{joiner}, @out;
}
EOR



#==========================================================================#

# Can send various files outside the catalog directory, for disk partition
# reasons, for example.

ParseVariables  Yes


---snip catalog.cfg -------


Regards,
David




David Radovanovic
WhatsTheBigIdea.com, Inc.
-- Creative ideas for the Web and beyond!
249 Partition Street
Saugerties, NY 12477
(845)247-0909
http://www.WhatsTheBigIdea.com




More information about the interchange-users mailing list