Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Adding a new template for modify

Quote Reply
Adding a new template for modify
Hi,
I have a PRE hook on user_modify_link that executes its part fine and it stops further the main code execution. Instead of returning to modify.cgi for displaying either error or success templates, it calls Links::SiteHTML::display with a separate template and values. However, the problem occurs since main code expects some return value and this is the error I get:
------------
Can't use string ("1") as a HASH ref while "strict refs" in use at /usr/local/etc/httpd/cgi-bin/classifieds/modify.cgi line 51.

---------

OK -makes sense. So, my question is: do you know the way around this? How do I add a new template on the existing modify.cgi (other than error and success?)

Thanks,

Masamoda :)


Quote Reply
Re: Adding a new template for modify In reply to
Hi,

I have had this problem before but it is the code itself I think and not actually loading the template that is causing the problem.

The template should load no problem with the correct code. Could you show what you have so people can try to give suggestions?.

Paul Wilson.
new - http://www.wiredon.net
Quote Reply
Re: Adding a new template for modify In reply to
The code is:
--------
sub some_sub {

$results = shift;
#some code...
GT::Plugins->action ( STOP );
Links::SiteHTML::display('my_template', $results);
return;
}
--------
If I return $results - it displays both my_template.html and modify_success.html. If I don't return anything - it gives me the error - which is understood, since modify.cgi ( _modify() in particular) expects hash in return. Now, obviously I will have to make a separate hook on 'site_html_modify_success' and try to handle it there...
I hope this was descriptive. If not, let me know, and I will try to give more details.

Thanks,

Masamoda :)

Quote Reply
Re: Adding a new template for modify In reply to
HI,

Yes I had the exact same problem with my plugin returning two templates on the same page....

You have GT::Plugins->action ( STOP ); in the code though before you load the template....are you sure that is correct?

Paul Wilson.
new - http://www.wiredon.net
Quote Reply
Re: Adding a new template for modify In reply to
Hi,

The STOP only stops the user_modify_link to happen. After that, the program will display either the success or error page. If you want to display a different template, you need to override one of those pages.

You could do this:

Code:
sub plg_user_modify_link {
my $results = shift;
..
GT::Plugins->action ( STOP );
return $results;
}
and then:

Code:
sub plg_site_html_modify_success {
my $tags = shift;
GT::Plugins->action ( STOP );
return Links::load_template ('new_template.html', $tags);
}
So the first one overrides the modify code, and the second one overrides the success page with your page.

You could make it conditional by doing something like:

Code:
sub plg_user_modify_link {
my $tags = shift;
if ( .. ) {
GT::Plugins->action ( STOP );
$tags->{override} = 1;
return $tags;
}
return $tags;
}

sub plg_site_html_modify_success {
my $tags = shift;
if ($tags->{override}) {
GT::Plugins->action ( STOP );
return Links::load_template ('new_template.html', $tags);
}
return $tags;
}
So you set $tags->{override} = 1 if you want to print a new template. Then your pre hook for modify_success checks to see if override was set, if so it aborts the regular template and prints out what you want.

Does this make sense, and help you do what you want?

Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: Adding a new template for modify In reply to
Thanks Alex - that's where I was heading...and it does help.

I'll keep you posted on how it worked.

Masamoda :)