"Fossies" - the Fresh Open Source Software Archive

Member "grails-core-5.2.4/grails-docs/src/test/resources/docs/ref/Tags/link.html" (14 Sep 2022, 69398 Bytes) of package /linux/www/grails-core-5.2.4.tar.gz:

Caution: In this restricted "Fossies" environment the current HTML page may not be correctly presentated and may have some non-functional links. You can here alternatively try to browse the pure source code or just view or download the uninterpreted raw source code. If the rendering is insufficient you may try to find and view the page on the grails-core-5.2.4.tar.gz project site itself.

(Quick Reference)


Creates an html anchor tag with the href set based on the specified parameters.


Example controller for an application called "shop":

class BookController {
    def list() {
        [books: Book.list(params)]

    def show() {
        [book : Book.get(params.id)]

Example usages for above controller:

<g:link action="show" id="1">Book 1</g:link>

<g:link action="show" id="${currentBook.id}">${currentBook.name}</g:link>

<g:link controller="book">Book Home</g:link>

<g:link controller="book" action="list">Book List</g:link>

<g:link controller="book" action="list" plugin="publishingUtils">Book List</g:link>

<g:link url="[action:'list',controller:'book']">Book List</g:link>

<g:link action="list" params="[sort: 'title', order: 'asc',
                               author: currentBook.author]">
     Book List

<g:link controller="book" absolute="true">Book Home</g:link>

<g:link controller="book" namespace="publishing">Publishing Book Home</g:link>

<g:link controller="book" base="http://admin.mygreatsite.com">Book Home</g:link>

Example Usage for a RESTful Resource:

static mappings = {
    "/books"(resources: 'book')
<g:link resource="book">Book Home</g:link>
<g:link resource="book" id="${book.id}">Book Show</g:link>
<g:link resource="book" action="create">New Book</g:link>

Example as a method call in GSP only:

<%= link(action:'list',controller:'book') { 'Book List' }%>

Results in:

<a href="/shop/book/list">Book List</a>



  • action (optional) - the name of the action to use in the link; if not specified the default action will be linked

  • controller (optional) - the name of the controller to use in the link; if not specified the current controller will be linked

  • resource (optional) - the name of the resource url mapping to use in the link; if not specified controller should be used

  • namespace (optional) - the namespace of the controller to use in the link

  • plugin (optional) - the name of the plugin which provides the controller

  • elementId (optional) - this value will be used to populate the id attribute of the generated anchor tag

  • id (optional) - the id to use in the link href, (often the id param passed to the controller)

  • fragment (optional) - The link fragment (often called anchor tag) to use

  • mapping (optional) - The named URL mapping to use to rewrite the link

  • method (optional) - The HTTP method specified in the corresponding URL mapping

  • params (optional) - a Map of request parameters

  • uri (optional) - a relative URI

  • relativeUri (optional) - Used to specify a uri relative to the current path.

  • url (optional) - a Map containing the action, controller, id etc.

  • absolute (optional) - If true will prefix the link target address with the value of the grails.serverURL property from application.groovy, or http://localhost:<port>; if there is no setting in application.groovy and not running in production.

  • base (optional) - Sets the prefix to be added to the link target address, typically an absolute server URL. This overrides the behaviour of the absolute property, if both are specified.

  • event (optional) - The name of a Webflow event to trigger for the flow associated with the given action. Requires the Webflow plugin.