Question

I have a page which displays a list of elements, but I want to be able to handle sorting, paging, tags, and searching of this list.

So, for example, I want the tag links/search box/page links to include all of the other parameters. How can I do this using template toolkit?

As an example, on the page

/example

the tag foo will link to /example?tag=foo. However, if the page represents a sorted search, the page may be

/example?search=bar&sort=name

so I want the tag link to include these parameters, so /example?search=bar&sort=name&tag=foo.

Was it helpful?

Solution

There are a number of additional parameters that automatically get passed to template toolkit. Here is the documentation:

https://metacpan.org/pod/Dancer::Template::Abstract

You will notice that one of them is params. So, within TT, you could build something like this:

    <a href="/example?search=<% params.search %>&sort=<% params.sort %>&tag=<% params.tag %>"> ... </a>

Of course, if you wanted to get fancier, you could add them only conditionally. For example:

     ... <% IF params.sort %>&sort=<% params.sort %><%END%> ...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top