> sub submenu_filter_factory {
>     my ($context) = @_;
>     return sub {
>         my $text = shift;
>         my $count = 1;

This should probably be my $count = 0;

>         $text =~ s[<h2>(.+?)</h2>][replace_tags( $context, $1, $count++ )]gie
> ;

You might want to add "s" to "gie" to handle multi-line headings (but
your hrefs and tags will need to be fixed too).  You might want to
ignore optional attributes too...

>
>         return $text;
>     }
> }
> 
> 
> sub replace_tags {
>     my ( $context, $tag, $count ) = @_;
>     my $stash = $context->stash;
> 
>     my $page = $stash->get( ['template', 0, 'page', 0 ] );
>     my $jump = '#' . $page . $count;
> 
>     # I'm lost here
>     $stash->set( ['sections', $count ], { href => $jump, text => $tag } );
>     $stash->set( 'IMPORT', $stash->get('sections') ); 
> 
>     return qq[<a name="$jump">\n<h2>$tag</h2>];
> }

The first $stash->set() looks fine.  I don't know what the second
$stash->set() is meant to do; it is likely not needed.

> So in my wrapper I PROCESS menu:  (and I'm sure this can be written better!)

The remaining problem likely has to do with localization of the stash.
INCLUDE (and WRAPPER) localize the stash, meaning a local copy of the
top level is made, and then restored when the INCLUDEd template is
finished.

I'm not 100% sure of your hierarchy, but if your filter is below
(inside) an INCLUDE or WRAPPER, then your sections variable won't
exist after the INCLUDE or WRAPPER.

Here's a quick test: add something this at the top:

    [% sections = []; %]

This pre-defines an empty array, whose entries (ie: sections.0, ...) will
now survive delocalization.

Also, I find the Dumper plugin is a great way to debug these kinds
of things since you can print out variables at various points to
make sure everything is ok.

Craig


Reply via email to