Gossamer Links Developers Guide
: Enhancing Gossamer Links
There are many different
ways you can enhance Gossamer Links. Plugins are the most advanced way and is a
great way to share your addition with others. However, if you just need to
add some code, or alter Gossamer Links so it works for you, there are a couple
different things you can do.
Running Custom Code:
Before you get into Plugins,
you may not even need them! The template system provides a robust way of
adding your own code to Gossamer Links. You can do this in one of two ways:
1. Go to Build->Template
Globals and you can add a perl subroutine. For instance, to display a list of the
top 5 links you could do:
sub {
my $vals = shift;
my $link_db = $DB->table ('Links');
$link_db->select_options ('ORDER BY Hits DESC', 'LIMIT 5');
my $sth = $link_db->select;
my $output = '';
while (my $link = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display('link', $link);
}
return $output;
}
|
The first argument is a hash
ref of tags that are already available on this page. Your function can
either return a hash ref making new tags available, or return HTML that will
be displayed to the user. In our case we simply queried the database,
formatted the top 5 links and returned the output.
Be sure to view our resource center
for a list of globals users have created that you can easily add.
2. Create your own module
with functions, and reference it:
<%Yourmodule::somefunc%>
and it will run somefunc
that should be found in Yourmodule.pm. Same rules apply.
Adding Custom Fields:
Adding fields is easy in Gossamer Links. To add a new field to the Links
table, simply click on Database->Links->Properties. Then at the bottom
click on Add Column. This will present you with the following options:
Column
Name |
|
This is the
name of the column, and must be a valid SQL name (so no
spaces, etc.) |
Column
Type |
|
This is a
select list of what type of data you will store. If you need
more then 255 characters, you should use a TEXT field. |
Column
Size |
|
This is the
length of the field and is only required for CHAR types. |
Column
Values
(Only for ENUM fields) |
|
If you are
using an ENUM (enumerated) type, then you need to enter the
values here. One value per line. For instance if you wanted to
add a column Status that could have values 'Cool', 'New',
'Popular', 'Reviewed' only, then you would enter those values
her, one per line. |
Not
Null |
|
Set
to Yes if the user must enter a value, if set to no, the
column can be left blank. |
Default |
|
Enter the
default value here, this will be what is shown when the user
clicks on add. |
Form
Display |
|
If your column
is named foo_bar then you can enter a pretty name that is used
when displaying the column (such as 'My New Column'). |
Form
Type |
|
A select list
of what type of form you want to use to display this field:
checkboxes, radio buttons, textareas, etc. |
Form
Size |
|
The SIZE
attribute of the form, this determines how large the form
appears in the admin. |
Form
Names
(Stored in Database) |
|
If
the form type is a select or checkbox, this list controls what
names are stored in the database. |
Form
Values
(Displayed on Form) |
|
If
the form type is a select or checkbox, this list controls what
values are displayed to the user. |
Form
Regex |
|
You can enter a
regular expression that all input must pass before being
submitted. |
Search
Weight |
|
This controls
whether the field is searchable by the user. The higher the
number, the more important the result is. |
|
When you hit submit, the
column will automatically appear in your Admin, and be available on your
templates as <%ColumnName%>. You must manually add it to the add and
modify forms for it to be available to users.
|