TSRef - TypoScript Reference
5.1.8. typolink:
Wraps the incoming value with link.
If this is used from parseFunc the $cObj->parameters-array is loaded with the link-parameters (lowercased)!
|
Property: |
Data type: |
Description: |
Default: |
|---|---|---|---|
|
extTarget |
target /stdWrap |
target used for external links |
_top |
|
target |
target /stdWrap |
target used for internal links |
|
|
no_cache |
boolean /stdWrap |
Adds a "&no_cache=1"-parameter to the link |
|
|
useCacheHash |
boolean |
If set, the additionalParams list is exploded and calculated into a hashstring appended to the url, like "&cHash=ae83fd7s87". When the caching mechanism sees this value, it calculates the same value on the server based on incoming values in HTTP_GET_VARS, excluding id,type,no_cache,ftu,cHash,MP values. If the incoming cHash value matches the calculated value, the page may be cached based on this. The [SYS][encryptionKey] is included in the hash in order to make it unique for the server and non-predictable. |
|
|
additionalParams |
string /stdWrap |
This is parameters that are added to the end of the url. This must be code ready to insert after the last parameter.
Example: '&print=1' '&sword_list[]=word1&sword_list[]=word2'
Applications: This is very useful when linking to pages from a searchresult. The searchwords are stored in the register-key SWORD_PARAMS and can be insert directly like this: .additionalParams.data = register:SWORD_PARAMS
NOTE: This is only active for internal links! |
|
|
addQueryString |
boolean |
Add the QUERY_STRING to the start of the link. Notice that this does not check for any duplicate parameters! This is not a problem (only the last parameter of the same name will be applied), but enable "config.uniqueLinkVars" if you still don't like it.
.method: If set to to GET or POST then then the parsed query arguments (GET or POST data) will be used. This settings are useful if you use URL processing extensions like Real URL, which translate part of the path into query arguments. It's also possible to get both, POST and GET data, on setting this to "POST,GET" or "GET,POST". The last method in this sequence takes precedence and overwrites the parts that are also present for the first method.
.exclude: List of query arguments to exclude from the link (eg L or cHash). |
|
|
wrap |
wrap |
Wraps the links. |
|
|
ATagBeforeWrap |
boolean |
If set, the link is first wrapped with ".wrap" and then the <A>-tag. |
|
|
parameter |
string /stdWrap |
This is the data, that ->typolink uses to create the link. The value is trimmed and if it's empty, ->typolink returns the input value untouched.
NOTE: If used from parseFunc, this value should be imported by: typolink.parameter.data = parameters : allParams
Examples: Internal links: integers (51): creates a link to page with uid = 51 filerefs (fileadmin/somedir/thedoc.html): creates a link to the file on the local server. strings (some_alias): creates a link to the page with alias = "some_alias"
External links: email-adresses (name@email.com): creates a link to the email-addr. domains (www.domain.com): creates link to http://-page
The input is parsed like this: First the parameter is splitted by character-space. This provides a way to pass more parameters. See "target" below here. If a "@" is in the string, it's an email If a period (.) is in the string AND if the period (.) is found before a slash (/) is found OR if a doubleslash is found, then it's a URL If a slash (/) is found, it's a filereference. If the file/directory does not exist on the server, the link is NOT made!
Now the input can be an alias or page-id. If the input is an integer it's a page-id, if it's two comma separated integers, it's a id/type pair, else it's an alias. For page-id's or aliases you can prepend a "#" mark with a number indication tt_content record number on the page to jump to! (if .section-property is present, it overrides this). If you insert only "#234" where "234" is the tt_content record number, it links to the current page-id Notice: The parameter can contain a keyword that hands over link generation to an external function. See example below this table!
Target Target is normally defined by the "extTarget" and "target" properties of typolink. But you may override this target by adding the new target after the parameter separated by a whitespace. Thus the target becomes the second parameter. If the "Target" parameter is set to the "-" character, then it's the same as no target passed to the function. This feature enables you to still pass a class as third parameter and title as fourth parameter without setting the target also.
Open in windows with fixed dimensions (JavaScript) It is possible to open the link in a window opened by JavaScript (with "window.open"). For this, just set the target value to "123x456" where 123 is the window width and 456 is the window height. You can also specify additional parameters to the function by entering them separated from the width and height with a colon ":". For instance "230x450:resizable=0,location=1" will disable resizing of the window and enable the location bar. Also see property "JSwindow".
Class If you specify a third parameter separated by whitespace in the parameter value this becomes the class-parameter of the link. This class parameter is inserted in the link-tag before any values from .ATagParams which means this class value will override any class value set in ATagParams (at least for MSIE). If set to "-", then it's the same as no class passed to the function. This feature enables you to still pass a title as fourth parameter without setting the class also.
Title The title attribute is normally specified via .ATagParams or directly via the .title property. But you may override this value by adding the desired title as the fourth parameter (parameters separated by whitespace) to typolink.
Examples of multiparameters: Consider this .parameter value passed to this function:
51 _blank blueLink
This would result in a link approx like this:
<A href="?id=51" target="_blank" class="blueLink"> |
|
|
title |
string /stdWrap |
Sets the title parameter of the A-tag. |
|
|
JSwindow_params |
string |
Preset values for opening the window. This example lists almost all possible attributes: status=1,menubar=1,scrollbars=1,resizable=1,location=1,directories=1,toolbar=1 |
|
|
returnLast |
string |
If set to "url" then it will return the URL of the link ($this->lastTypoLinkUrl) If set to "target" it will return the target of the link. So, in these two cases you will not get the value wrapped but the url or target value returned! |
|
|
section |
string /stdWrap |
If this value is present, it's prepended with a "#" and placed after any internal url to another page in TYPO3. This is used create a link, which jumps from one page directly the section on another page. |
|
|
ATagParams |
<A>-params /stdWrap |
Additional parameters
Example: class="board" |
|
|
userFunc |
function-name |
This passes the link-data compiled by the typolink function to a user-defined function for final manipulation. The $content variable passed to the user-function (first parameter) is an array with the keys "TYPE", "TAG", "url", "targetParams" and "aTagParams". TYPE is an indication of link-kind: mailto, url, file, page TAG is the full <A>-tag as generated and ready from the typolink function. The latter three is combined into the 'TAG' value after this formula:
<a href="'.$finalTagParts['url'].'"'. $finalTagParts['targetParams']. $finalTagParts['aTagParams'].'>
The userfunction must return an <A>-tag. |
|
[tsref:->typolink]
Using link handlers
A feature (added in TYPO3 4.1) allows you to register a link handler for a keyword you define. For example, you can link to a page with id 34 with "<link 34>" in a typical bodytext field which converts <link> tags with "->typolink". But what if you have an extension, "pressrelease", and wanted to link to a press release item displayed by a plugin on some page you don't remember? With this feature its possible to create the logic for this in that extension.
So, in a link field (the "parameter" value for ->typolink) you could enter "pressrelease:123":
![]()
Some TypoScript will usually transfer this value to the "parameter" attribute of the ->typolink call. When "pressrelease:123" enters ->typolink as the "parameter" it will be checked if "pressrelease" is a keyword with which a link handler is associated and if so, that handler is allowed to create the link.
Registering the handler for keyword "pressrelease" is done like this:
$TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_content.php']['typolinkLinkHandler']['pressrelease'] = 'EXT:pressrelease/class.linkHandler.php&tx_linkHandler';
The class file "pressrelease/class.linkHandler.php" contains the class "tx_linkHandler" which could look like this:
class tx_linkHandler {
function main($linktxt, $conf, $linkHandlerKeyword, $linkHandlerValue, $link_param, &$pObj) {
$lconf = array();
$lconf['useCacheHash'] = 1;
$lconf['parameter'] = 34;
$lconf['additionalParams'] = '&tx_pressrelease[showUid]='.rawurlencode($linkHandlerValue);
return $pObj->typoLink($linktxt, $lconf);
}
}
In this function, the value part after the keyword is set as the value of a GET parameter, "&tx_pressrelease[showUid]" and the "parameter" value of a new ->typolink call is set to "34" which assumes that on page ID 34 a plugin is put that will display pressrelease 123 when called with &tx_pressrelease[showUid]=123. In addition you can see the "userCacheHash" attribute for the typolink function used in order to produce a cached display.
The link that results from this operation will look like this:
<a href="index.php?id=34&tx_pressrelease[showUid]=123%3A456&cHash=c0551fead6" >
The link would be encoded with RealURL and respect config.linkVars as long as ->typolink is used to generate the final URL.