Gossamer Forum
Home : Products : Gossamer Links : Discussions :

What's the difference between <%links%> and <%links_loop%>

Quote Reply
What's the difference between <%links%> and <%links_loop%>
Surely there is a simple explanation for this, but I can't find the answer anywhere. What is the purpose of links_loop and category_loop and related_loop as opposed to the "non_loop" globals??

From the brief definition in the template, the only difference is that one is a loop and the other a list, but what's a loop??? Crazy
Quote Reply
Re: [AtoZ] What's the difference between <%links%> and <%links_loop%> In reply to
A loop basically lets you do things that would couldn't with a basic tag. I.e <%links%> is quite a flexible tag, in that you can use things like <%if Field%>show something<%endif%>, but with a loop, you can do much better stuff...like making multiple colums for the links (see resource section, there is a global I believe)...the loops just make thing slightly easier for people doing more advanced stuff.

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [AtoZ] What's the difference between <%links%> and <%links_loop%> In reply to
Instead of Links SQL building output itself and sending it to the template in one tag, ie <%links%>, a loop stores all the data in an arrayref of hashrefs and allows you to customize the display in your template.

If you were to print the loop it would look like:
Code:
[
{ ID => '1', Title => 'Foo', URL => 'http://www.aol.com' etc... },
{ ID => '2', Title => 'Foo', URL => 'http://www.aol.com' etc... },
{ ID => '3', Title => 'Foo', URL => 'http://www.aol.com' etc... },
]

All those hash keys like <%ID%> etc can then be used in your template.
Quote Reply
Re: [AtoZ] What's the difference between <%links%> and <%links_loop%> In reply to
put a

<%if Status eq 'Administrator'%>
<%GT::Template::dump%>
<%endif%>

at the bottom of category.html and run it with page.cgi

You'll see very clearly what it does :)

The if prevents non-admin users from seeing it.


PUGDOG´┐Ż Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [Andy] What's the difference between <%links%> and <%links_loop%> In reply to
Thanks to all of you for taking the time to explain!

Is there not anything documenting this feature? I didn't even know it existed, and, WOW, the possibilities seem almost endless. I have found the example for splitting up sponsored and non-sponsored links, but I'd like to see other examples. I have perused the forum listings and have found a few, but it would be nice to have this functionality explained in the docs somewhere since the person who created it knows the most about what it can do. (Alex, please???) If I am just missing it, please point me in the right direction.

I posted a message a few weeks ago about wanting to split up my category listings, and I was SO close! (http://www.gossamer-threads.com/...i?post=199742#199742) All I needed was to use <%links_loop%> instead of just <%links%>. I am surprised no one pointed that out because the solution was so obvious, and SO SIMPLE!

OKAY, now I have another question. Let say I want to display all the links that have a field=something AND another field=something else. I have tried using

<%loop links_loop%>
<%if field eq 'something'%>
<%if anotherfield eq 'somethingelse'%>
<%include link.html%>
<%endif%>
<%endif%>
<%endloop%>

but it doesn't work (no results). What can I do?

Last edited by:

AtoZ: Jun 29, 2002, 2:08 PM
Quote Reply
Re: [AtoZ] What's the difference between <%links%> and <%links_loop%> In reply to
In Reply To:
I have found the example for splitting up sponsored and non-sponsored links


Could you please post your way of splitting up sponsored and non-sponsored links?

Thanks!
Quote Reply
Re: [Payooo] What's the difference between <%links%> and <%links_loop%> In reply to
Glad to help:

It's explained in this post--
http://www.gossamer-threads.com/...i?post=155543#155543
Quote Reply
Re: [AtoZ] What's the difference between <%links%> and <%links_loop%> In reply to
Hi,

You can find some info on loops in the admin help at:

http://www.gossamer-threads.com/perl/links-sql2/admin/admin.cgi?do=help&topic=help_templates_syntax.html

and:

http://www.gossamer-threads.com/perl/links-sql2/admin/admin.cgi?do=help&topic=/GT/Template.html

As for your test, try putting some else's in there to see what's going wrong:

<%if field eq 'something'%>
..
<%else%>
field is set to '<%field%>'
<%endif%>

Also, try the <%GT::Template::dump%> suggestion to see what everything is set to.

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] What's the difference between <%links%> and <%links_loop%> In reply to
Thanks for the info!! I hadn't even realized there was additional "help" in the admin. That explains it very well. I think previous versions referred only to the support forum in the help section, so I had not been in the habit of looking there. (I've been using Links for more than 3 years, since 2.0, so it's been hard to keep up with all the changes!)

As for my test, my syntax is all correct I think (?) but ... I discovered that the problem is that I am wanting to pull in links from any category, not just the category I am on (and since there is nothing matching those ifs in that category, then I get no results). To get the records I need, I could create the same kind of effect by linking to search results like search.cgi?field=something&anotherfield=somethingelse, but I'd like it to be static and to be able to have those specific records on each category page without actually having to put each record in multiple categories.

so... my new question is, How can I build pages that pull in records that have fields equal to whatever I choose? Can this be accomplished with a loop, or is it more involved?