////
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
////


== createLinkTo


WARNING: Deprecated: Use xref:resource.html[resource] instead.


=== Purpose


Creates a link that can be used where necessary (for example in an href, JavaScript, Ajax call etc.)


=== Examples


Example controller for an application called "shop":

Example usages for the "shop" app:

[,xml]
----
<!-- generates "/shop/css/main.css" -->
<g:createLinkTo dir="css" file="main.css" />

<!-- generates "https://portal.mygreatsite.com/css/main.css" -->
<g:createLinkTo dir="css" file="main.css" absolute="true"/>

<!-- generates "https://admin.mygreatsite.com/css/main.css" -->
<g:createLinkTo dir="css" file="main.css" base="https://admin.mygreatsite.com"/>
----

Example as a method call in GSP only:

[source,xml]
----
<link type="text/css" href="${createLinkTo(dir:'css',file:'main.css')}" />
----

Results in:

[source,xml]
----
<link type="text/css" href="/shop/css/main.css" />
----


=== Description


Attributes

* `dir` (optional) - the name of the directory containing the resource
* `file` (optional) - the name of the resource file
* `absolute` (optional) - If `true` will prefix the link target address with the value of the `grails.serverURL` property from the application configuration, or http://localhost:8080 if there is no setting in the config 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.

