[TYPO3] Mark external links
Robert Markula
robert.markula at gmx.net
Tue Jul 18 16:15:10 CEST 2006
JoH wrote:
>>>> I'm trying to find a way to automatically mark external links with a
>>>> little icon in front of the link and a standard link title text.
>>>> I am searching for a solution whick works for all content elements,
>>>> be it tt_content, tt_news or tt_products.
>>>> Is this possible with typoscript?
>>> Thanks to all who helped me with this problem. I use Sebastian's idea
>>> and it works great!
>>>
>>> As promised I've created a WIKI [1] that explains the different
>>> methods to mark external links.
>>>
>>> Cheers,
>>> Ro
>>>
>>> [1] http://wiki.typo3.org/index.php/External_links
>> And now the inevitable question.... What if you don't want an actual
>> image, but instead want the link to just have a class that handles
>> the icon?
>
> And other questions regarding the TypoScript version:
>
> What if the link points to an alias?
> Alias != intval(Alias)
>
> What if it points to an anchor on the same page?
> 123#123 != intval(123#123)
>
> What if the first part is a UID but it is followed by 3 other parts for
> target, class and title?
> 123 _top linkclass linktitle != intval(123 _top linkclass linktitle)
>
> The interesting thing with typolink is, that it already takes care of
> internal and external links and renders them accordingly.
> Each external link, be it with or without http://, www. or whatever, will be
> recognized an prepended "http://" or "mailto:".
> So you just have to check for the existence of http:// or mailto: _after_
> the link has been created by typolink and then create a wrap based on a
> constant.
> Internal links will never have http:// or mailto: in front of them, since
> they point to index.php or a path on the same server if you are using
> realURL or link to files.
>
> If you want to do different checks, the easiest way is to put the link into
> a register and call it for the checks, so that you just have to create the
> link once.
> You can split it by ":" before you put it into the register since the
> interesting part for external links will be always in before this separator.
>
> So this one will do the job:
>
> lib.parseFunc.tags.link {
> typolink.parameter.append = LOAD_REGISTER
> typolink.parameter.append {
> isExternal {
> cObject = TEXT
> cObject {
> typolink.parameter.data = parameters:allParams
> typolink.returnLast = url
> }
> split {
> token = :
> cObjNum = 1||2
> 1 = TEXT
> 1.current = 1
> }
> }
> }
> outerWrap.cObject = CASE
> outerWrap.cObject {
> key.data = register:isExternal
> default = TEXT
> http = TEXT
> http.value = {$externalLinkWrap}
> mailto = TEXT
> mailto.value = {$mailtoLinkWrap}
> }
> }
>
> lib.parseFunc_RTE.tags.link {
> typolink.parameter.append <
> lib.parseFunc.tags.link.typolink.parameter.append
> outerWrap < lib.parseFunc.tags.link.outerWrap
> }
>
> You can see it in action here:
> http://www.4any1.de/index.php?id=2350&no_cache=1
>
> In the debug table on top of the page you can see the original values that
> are handed over to the typolink function.
> I left the constants empty, so that you can see how they are used.
> You can fill a real wrap like <div class="externallink">|</div> or just the
> desired img-tag <img src="whatever" /> into the constant.
>
> Advantages:
> No userFunc necessary
> Can be modified easily since there are no hardcoded tags
> Can be extended easily by adding another split to the LOAD_REGISTER and more
> variants to the CASE
>
> Have fun with it
>
> Joey
Exactly that's what I was so desperately looking for all the time.
Updated the WIKI accordingly. Many many thanks joey!
Cheers,
Ro
More information about the TYPO3-english
mailing list