# Gossamer Links Help

Table of Contents

Template Syntax

Gossamer Links template engine is powered by our GT::Template module. For a complete list of all the functionality available by this module, be sure to read it's documentation.

Gossamer Links provides a very straight forward way of templates. If you are familiar with ASP or PHP, then this should be no problem. Simply, each template has a set of tags on it that get replaced with HTML when the page is displayed. So for example, on the home page (home.html template), there is a <%category%> tag. This tag will be replaced with a full list of all the top level categories by Gossamer Links.

Tags:
Any tag in Gossamer Links always starts with a <% and ends with %>. Everything in between will be replaced. White space does not matter, so:

    1: <%category%>
    2: <%       category         %>
    3: <%
            category
    %>

will all do the same thing.

Variables:
By default anything inside of a <% .. %> tag is considered a variable, and will just be replaced with it's value. In the search results template (search_results.html), <%link_results%> gets replaced with a list of matching links, and <%category_results%> gets replaced with a list of matching categories.

Template Comments:
Anything inside <%-- and --%> is considered a comment and the template parser will remove these (so even if the user views source, they will not be visible). The default templates use comments to let you know what special tags are available on that template.

When Variables are not Enough:
Quite often you need a bit more control on the layout. For instance, say you want to display something different if no matching category results were found. For this, you can use if, else, and elsif. It's pretty straightforward:

    <%if category_results%>
       <table>
         <tr><td>Here are your category matches: <%category_results%></td></tr>
       </table>
    <%else%>
       Sorry, but no matching categories were found!
    <%endif%>

Each if statement must end with a matching endif statement. Here's another example on the add form. If the user submitted the form and there was an error, we need to display that error to the user:

    <%if error%>
       <p><font color="red">Oops, there was a problem with your submission:
             <%error%>
       </font></p>
    <%endif%>

That html between the if and endif tags will only get displayed if there was an error on the addition. Also available are <%ifnot ..%> and <%unless ..%>.

Loops:
If you are feeling a bit overwhelmed, then you can skip this part. Loops are an advanced feature that provide complete control over the layout of the directory. Perhaps you don't like the fact that the same link.html template is used when displaying a list of search results and for displaying the links in the category page. Well, by default Gossamer Links only provides you with a <%link_results%> tag, so there is not much you can do, right? Wrong! For all of the major tags, you can use loops instead. Let's look at search results. Instead of:

    <p>Here are your matching links:<br><br><%link_results%></p>

You could do:

    <p>Here are your matching links:<br><br>
    <%loop link_results_loop%>
        <a href="<%URL%>"><%Title%></a>: <%Hits%>
    <%endloop%>

So inside the <%loop%> and <%endloop%> tag you have a series of links, and you can use any link attribute you like. However, don't forget you can also use includes, so you could do:

    <p>Here are your matching links:<br><br>
    <%loop link_results_loop%>
        <tr><td><%include link.html%></td></tr>
    <%endloop%>

Now link.html will be loaded and parsed!

Much More:
Be sure to read our GT::Template docs for even more things you can do like math operations, function calls, and much more!

Table of Contents