In TYPO3's Fluid or in Fedext/vhs, is there a viewhelper that can convert
http://www.stackoverflow.com/questions/ask
into
www.stackoverflow.com
?
PS: that's the goal:
<f:format.raw><f:link.external uri="{item.link}">{item.just-display-the-domain}</f:link.external></f:format.raw>
EDIT (adapting the question to the answer I got): If I have to build a custom view helper, how do I proceed?
I really doubt if there would be any sensible reason for adding this kind of VH into the core, de facto, writing custom VH is like a piece of cake (when you finally realize it is) so simple formatters can be created by devs in their custom tool exts just in minutes.
Ie. in TYPO3
4.x
assuming that you have a custom extension with keyurs
all you need to do is create one proper class, containingrender($params)
method and extendingTx_Fluid_Core_ViewHelper_AbstractViewHelper
class:/typo3conf/ext/urs/Classes/ViewHelpers/GetDomainViewHelper.php
:Next in your templae declare its namespace and... that's all, you can use it:
Take special attention about letter case in things like
Tx_Urs_ViewHelpers...
etc.More details in http://docs.typo3.org/typo3cms/ExtbaseFluidBook/8-Fluid/8-developing-a-custom-viewhelper.html
In TYPO3 ver. 6.x
Things works preaty similar the main change of course is new namespacing
/typo3conf/ext/urs/Classes/ViewHelpers/GetDomainViewHelper.php
:In templates:
Of course in both cases instead of using hardcoded links you will use:
It's a little bit cumbersome and not very efficient, but it should work and would of course prevent the need for a custom ViewHelper class:
Where
{url}
can come from anywhere, as long as it contains a fullhttp://
or other protocol prefix. The line above of course explodes the URL into parts separated by/
then slices off the first three segments and re-joins those using/
. Or it simply picks offset2
(which would be the full domain without protocol) and returns that single element. The result should be an url to the domain of the link, with or without protocol, without trailing slash (which you may or may not want to add yourself after cutting the URL).Cheers, Claus
All ViewHelper are located at
typo3/sysext/fluid/Classess/ViewHelper
. There are also examples in the header of each file. All ViewHelper of Fedext can be reviewed on the website.