The servlet bean SiteLinkDroplet can generate URLs that reference other sites. You can use this servlet bean to write page code that generates links to different sites and paths, depending on the current site context.
SiteLinkDroplet uses input parameters siteId
and path
to generate a URL as follows:
If input parameter... | Contains... | Then... |
---|---|---|
| Site ID | Use production URL configured for this site. |
| (parameter omitted) | Use the current site. |
| Leading forward slash ( | Replace old path with new path relative to site root. |
| No leading forward slash ( | Make specified path relative to current page. |
| (parameter omitted) | Retain old path relative to site root. |
The output parameter url
contains the generated URL, which you can use to set a link to the desired site.
SiteLinkDroplet also provides the following optional input parameters:
queryParams
: Appends the specified query parameters to the generated URL.protocol
: Specifies the protocol to use—http
orhttps
—in the generated URL. If omitted, the protocol is set from theSiteURLManager
propertydefaultProtocol
.inInclude
: If SiteLinkDroplet is invoked inside an included page, you can setinInclude
to true in order to specify that the generated URL contains the included page’s path relative to the parent page.
The following examples demonstrate two use cases:
Site ID specified, path omitted
In the following example, the following conditions apply:
Current page URL:
http://FirstSite.com/dir/index.jsp
Production site URL of site
mySite
:SecondSite.com
.
<dsp:droplet name="SiteLinkDroplet"> <dsp:param name="siteId" value="mySite"/> <dsp:oparam name="output"> <dsp:getvalueof var="newUrl" param="url" vartype="java.lang.String"> <dsp:a href="${newUrl}>"> Click Here!</dsp:a> </dsp:getvalueof> </dsp:oparam> </dsp:droplet>
This generates the following link:
<a href="http://SecondSite.com/dir/index.jsp">Click Here!</a>
Site ID omitted, path replaced
If the current page is http://FirstSite.com/dir/index.jsp
, the following code generates this link:
<a href="http://FirstSite.com/home/index.jsp">Click Here!</a>
<dsp:droplet name="SiteLinkDroplet"> <dsp:param name="path" value="/home/index.jsp"/> <dsp:oparam name="output"> <dsp:getvalueof var="url" param="url" vartype="java.lang.String"> <dsp:a href="${url}"> Click Here!</dsp:a> </dsp:getvalueof> </dsp:oparam> </dsp:droplet>