Gossamer Forum
Home : Products : Links 2.0 : Discussions :

How do I use contact name and email of contact in templates?

Quote Reply
How do I use contact name and email of contact in templates?
I want to create new templates and to use the contact name and contact email in a few templates. I see them in the data files but cannot find any variables in site_html_templates.pl or any where else to be used. Can someone tell me the code I must ad... or point me to a thread that will allow me to add this.
Thanks
Tim
Quote Reply
Re: How do I use contact name and email of contact in templates? In reply to
Depends on the template file. You just use, for example, <%Contact Name%> and <%Contact Email%> in link.html. In general, if the subroutine in site_html_templates.pl passes the %rec variable to a template, then those tags can be used in the template.

I hope this helps.
Quote Reply
Re: How do I use contact name and email of contact in templates? In reply to
One template in particular that I want to add <%Contact Name%> and <%Contact Email%> to is detail.html. I want to put the author in stories posted and make the <%Contact Name%> a hotlink using <%Contact Email%> .
How would I code this in site_html_templates.pl and any other modules.

I just tried to figure some of this out myself with what you stated in your last reply. Am I on the right track here?

Is the below routine where you might be talking about as far as placeing code for this? Do I have to touch any other routines or modules to acomplish this feat? I do not want to mess up anything as I only have about 2 years of Perl experience so I am still "weak brained" on some of what the coding does but eager to learn. I am trying to understand what the "my %rec = @_;" is doing as far as building an array. Where does the @_; get its data from? And still trying to find out what the expression "=>" represents if possible Smile

For others interested in doing this same thing this cut is from site_html_templates.pl and has some addtions :
sub site_html_link {
# --------------------------------------------------------
# This routine is used to display what a link should look
# like.

my %rec = @_;
#What I want is to have the "Title" in the current Resource Center Template to link
#to a review and then have the review link to the actual site.
my $details_cnt = "";
if ($build_detailed) {
$details_cnt++;
}
# end of change1



# Set new and pop to either 1 or 0 for templates.
($rec{'isNew'} eq 'Yes') ? ($rec{'isNew'} = 1) : (delete $rec{'isNew'});
($rec{'isPopular'} eq 'Yes') ? ($rec{'isPopular'} = 1) : (delete $rec{'isPopular'});

#return &load_template ('link.html', {
# detailed_url => "$db_detailed_url/$rec{'ID'}$build_extension",
# %rec,
# %globals
# });

#added for change1 Detail change
return &load_template ('link.html', {
detailed_url => "$build_detail_url/$rec{'ID'}$build_extension",
Details => $details_cnt,
%rec,
%globals
});
}


Thanks
Tim


[This message has been edited by timryan (edited July 09, 1999).]
Quote Reply
Re: How do I use contact name and email of contact in templates? In reply to
When nph-build.cgi calls sub site_html_link in the various routines that build links, it passes an array the contains all the fields for that record (out of links.db). The my %rec = @_; line assigns those fields to the %rec array, which in turn, is passed to the template that the subroutine calls.

You are editing in the wrong place. You need to look at sub site_html_detailed since sub site_html_link only builds the link itself and had nothing to do with the detailed pages other than providing a URL to them.

The sub site_html_detailed does pass %rec to the detailed.html template, so you should be able to use <%Contact Name%> and <%Contact Email%> inside the detailed.html file with no problem.

I hope this helps.
Quote Reply
Re: How do I use contact name and email of contact in templates? In reply to
Thank bobsie, You have defenitely shed some light on my understanding here. Which makes me bring up a question. I added a new field in links.def.
Details => [14, 'alpha', '40x3', 32500, 0, '', '']

Called Details. Will this conflict with the variables created/added in the site_html_templates.pl mod?
Specifically in question is the line added...
Details => $details_cnt,
in the sub site_html_link routine. Not sure what that line does. Looks like it is feeding contents of variable "Details" into the $details_cnt. But not sure what is suppose to be in "Details" when used in this code.
I just went back to the Thread at
http://www.gossamer-threads.com/scripts/forum/resources/Forum11/HTML/000668.html
to refresh and better understand all this now with this new sent knowledge you have given me. Smile
Is there a conflict here with the variable "Details" or am I confusing my self on this?
What does the "=>" do for us in the latter code. (Just so you know I am not to lazy here... I did try and look up the answer on this in my "PERL 5 by Example" book, with know luck on understanding what "=>" is doing).


[This message has been edited by timryan (edited July 09, 1999).]

[This message has been edited by timryan (edited July 09, 1999).]
Quote Reply
Re: How do I use contact name and email of contact in templates? In reply to
As I originally wrote the instructions, the purpose of the $details_cnt and the Details => $details_cnt line was for use in the link.html file (I originally called it my $details, not $details_cnt). It is not a counter but, rather, a flag. When initially declared, it was null. If the variable, $build_detailed was set to 1 in links.cfg, the $details variable was incremented so that it would also contain 1.

Inside link.html, you could then use this code:

Code:
<%if Details%>
<ul><li><a class="link" href="<%detailed_url%>"><%Title%></a>
<%endif%>
<%ifnot Details%>
<ul><li><a class="link" href="<%db_cgi_url%>/jump.cgi?ID=<%ID%>"><%Title%></a>
<%endif%>

That way, the link would be for the detailed view instead of jump.cgi. The jump.cgi link would/should be inside the detailed file.

There should have been no reason to add Details to links.def.

I hope this helps.

[This message has been edited by Bobsie (edited July 10, 1999).]
Quote Reply
Re: How do I use contact name and email of contact in templates? In reply to
Thanks, I have links.html set up like that. Not sure how you can say I did not have to add a field though. Perhaps I am missing something here as Details seems to work find now... unless, as I use other modules later on I might run into a problem with how I have it set up? The original (and current) resource template (add.cgi) has 7 fields being passed.
Title:
URL:
Category:
Short Description:
Full Details:
Contact Name:
Contact Email
<<<
Upon testing I found the Short Description passed into the db Description field... but the Full Details passes into Never.. Never.. land. This is why I added the details field; to catch the "Detail" variable in the DB... that was passed from the add.cgi The current links.def looked like this>>

%db_def = (
ID => [0, 'numer', 5, 8, 1, '', ''],
Title => [1, 'alpha', 40, 75, 1, '', ''],
URL => [2, 'alpha', 40, 75, 1, 'http://', '^http|news|mailto|ftp'],
Date => [3, 'date', 15, 15, 1, \&get_date, ''],
Category => [4, 'alpha', 0, 150, 1, '', ''],
Description => [5, 'alpha', '40x3', 500, 0, '', ''],
'Contact Name' => [6, 'alpha', 40, 75, 1, '', ''],
'Contact Email' => [7, 'alpha', 40, 75, 1, '', '.+@.+\..+'],
Hits => [8, 'numer', 10, 10, 1, '0', '\d+'],
isNew => [9, 'alpha', 0, 5, 0, 'No', ''],
isPopular => [10, 'alpha', 0, 5, 0, 'No', ''],
Rating => [11, 'numer', 10, 10, 1, 0, '^[\d\.]+$'],
Votes => [12, 'numer', 10, 10, 1, 0, '^\d+$'],
ReceiveMail => [13, 'alpha', 10, 10, 1, 'Yes', 'No|Yes'],
<<<<<<<<

OH! you are right about the $details_cnt... The habit just comes from my old program schooling days. When I increment a variable I like to decribe it as such for readability (and an easy reminder that it is a counter (or flag) when used in other parts of my programs. Hope this did not change the results here or in any other modules?!@ I come from an old Basic programing background so I determine the expression of "=>" meaning "equal to or greater than" expression. I am still trying to determine Perls high-leveled-hidden meanings of certain code usages.
Thanks for your time on this. Smile



[This message has been edited by timryan (edited July 10, 1999).]
Quote Reply
Re: How do I use contact name and email of contact in templates? In reply to
You know, I think this is the first time that you mentioned the fact that you are working with the Resource Center templates. No wonder I was confused; we haven't been on the same sheet of music. If you did mention it, I missed it.

In the context, "ID => [0, 'numer', 5, 8, 1, '', ''],", the "=>" does not mean equal to or greater than (">=" means that); what it is is more of a pointer to a list or, in the case of template variables, a pointer to the variable. At least, that is how I view it. According to my Perl5 programming book, it is a comma operator.

For example, it says that when you see:

Quote:
link => $link

the result of evaluating the value on the left is discarded and the value on the right is returned. To me, it is saying use the contents of the variable on the right whenever the value on the left is referenced; so the left side points to the right side (it even looks like a pointer). Smile

I still am learning about Perl every day. Sometimes it amazes me and sometimes it drives me nuts!
Quote Reply
Re: How do I use contact name and email of contact in templates? In reply to
Thanks for the nice lesson bobsie. Smile