Please bear with me as I've just started working with Mason. I'm
working on a legacy Mason-built web-app which lets users search and
view details of my company's area rugs. Unfortunately the original
developer didn't  take the time to create the presentational logic
necessary to give each page it's own title; at first every html page
generated by Mason had the same title tag.

Following the advice on the Masonhq site, I defined a default title
method in the autohandler and called it like so <& SELF:title &>,
then defined custom title methods in the detail page files. The
problem is, I need dynamic content in the product title, and the
variables I have to work with in product-detail.mhtml (declared in an
init blovk) don't have the right scope to be used in the method
definition.

I thought I had found the answer when I read that you can take your
content from the  <%init> block and put it in a <%shared> block,
instead, thus making the variable/s available to any method
definitions whithin that file.

The problem is, I get this error after  wrapping the init block in a
shared block instead:

Global symbol "$item_id" requires explicit package name

I figure I must be missing something major about how the init and
shared blocks work. Here are the files in question:

----------------Autohandler-----------

...some html...

<title><& SELF:title &></title>

...some more html...

% $m->call_next();

<%method db_connect>
% $dbh = RugUtil::db_connect(...db details...);
% return 1;
</%method>

...call the footer...

<%method title>
Default Title
</%method>

-----------DetailPage.mhtml-----------

<%method title>
Product Detail Page
</%method>

...some html and embedded <% ... %> tags ...

<%init>

my $drl = &RugOps::retrieve_rug($dbh, item_id => $item_id, _public => 1)
        ->{results};
ref $drl and scalar @$drl == 1
        or die("No such rug '$item_id'.\n");
my $item = $drl->[0];

# Figure out if this rug is already in user's gallery, so we know which
# button to display.
my $in_gallery = 0;
if (my $user = $session{public_user}) {
    # Heresy!
    my $real_id = $item->{_real_id};
    my $q_user = $dbh->quote($user);
    my $sql = qq/SELECT COUNT(*) FROM user_item INNER JOIN user
        ON user_item.User = user.ID
        WHERE user.Name = $q_user AND user_item.Item = $real_id/;
    if ($dbh->selectcol_arrayref($sql)->[0]) {
        $in_gallery = 1;
    }
}

</%init>

<%args>
$item_id
</%args>

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Mason-users mailing list
Mason-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mason-users

Reply via email to