Documentation · ViewHelper reference

Format / CropViewHelper


Use this view helper to crop the text between its opening and closing tags.

Examples

Defaults

<f:format.crop maxCharacters="10">This is some very long text</f:format.crop>

Output

This is...

Custom suffix

<f:format.crop maxCharacters="17" append=" [more]">This is some very long text</f:format.crop>

Output

This is some [more]

Don't respect word boundaries

<f:format.crop maxCharacters="10" respectWordBoundaries="false">This is some very long text</f:format.crop>

Output

This is so...

Don't respect HTML tags

<f:format.crop maxCharacters="28" respectWordBoundaries="false" respectHtml="false">This is some text with HTML tags</f:format.crop>

Output

This is some text with 

Inline notation

{someLongText -> f:format.crop(maxCharacters: 10)}

Output

someLongText cropped after 10 characters...
(depending on the value of {someLongText})

/
  • Tag usage example

    <f:format.crop maxCharacters="123" append="'...'" respectWordBoundaries="1" respectHtml="1">
    	<!-- tag content - may be ignored! -->
    </f:format.crop>
  • Inline usage example

    {f:format.crop(maxCharacters: 123, append: ''...'', respectWordBoundaries: 1, respectHtml: 1)}

Arguments

Argument Description Type
append

What to append, if truncation happened

string
maxCharacters

Place where to truncate the string

integer
respectHtml

If TRUE the cropped string will respect HTML tags and entities. Technically that means, that cropHTML() is called rather than crop()

boolean
respectWordBoundaries

If TRUE and division is in the middle of a word, the remains of that word is removed.

boolean
Required attribute

Revision history

commit 38ebcedd944471b83d9293b648264fd3e65634f1
Author: Bastian Waidelich <*****@typo3.org>
Date:   Tue May 5 20:52:33 2009 +0000

    Fluid:
    * Changes backported from FLOW3:
      * major cleanup and refactoring of core and view helper classes & comments
      * added validation for boolean arguments in AbstractViewHelper
      * added initialize-method to AbstractViewHelper, that is called before render(). This was especially needed for tagbased viewhelpers.
      * renderChildren() now directly calls evaluateChildNodes() on the respective view helper node allowing us to render objects/arrays.
      * improved boolean type conversion for arguments in ViewHelperNode.
      * added TagBuilder class, re-wrote all tag based view helpers to use it (see form view helpers for some examples)
      * ViewHelperArguments collection got a new method "hasArgument()" that returns TRUE when the specified argument exists and is not NULL
    * tx_fluid changes:
      * Improved fake object factory. Now objects are injected to subclasses and implementations of the specified classes/interfaces.
      * cleaned up and tweaked view helpers. Removed Parsefunc, Stdwrap and TypoScript view helpers for now. Added CObject, If/Then/Else, EmailLink, Crop, Currency, Debug, HTML, Nl2br, Image view helpers. Thanks to Sebastian Böttger, Christopher Hlubek, Niels Pardon, Andreas Pattynama for the help!
    * Note: Unit tests not fully backported yet.

commit 27bbf6507db26ae9d53054ce908df203beefc3c8
Author: Bastian Waidelich <*****@typo3.org>
Date:   Sat May 16 18:43:53 2009 +0000

    tx_fluid:
     * !!!changed view helpers once again!!! link view helpers reside in the link subfolder now. For each link view helper there is a corresponding uri helper now. Check out https://svn.typo3.org/TYPO3v4/CoreProjects/MVC/viewhelpertest for a working example.
     * TagBuilder->setContent does not apply htmlspecialchar() on the the tag contents, as that does not really makes sense - if you really need to escape tag contents, you gotta do it yourself now.

commit 50af6b9c08d04e3e1d4ce56a499a9a3d4b84efc3
Author: Sebastian Kurfürst <*****@typo3.org>
Date:   Thu May 28 21:45:46 2009 +0000

    Fluid:
    * Backported major changes from Fluid v5 to Fluid v4
    * !!! Many of these changes are not backwards-compatible! Please read this if you have written custom ViewHelpers!
    * Introduced Shorthand Syntax for calling ViewHelpers
    * Core:
    ** Lots of internal cleanup and refactorings.
    ** !!! Complete restructuring into subpackages.
    * ViewHelpers:
    ** !!! The base classes of ViewHelpers changed to Tx_Fluid_Core_ViewHelper_AbstractViewHelper and Tx_Fluid_Core_ViewHelper_TagBasedViewHelper. Please adjust your ViewHelpers!
    ** !!! $this->variableContainer has been renamed to $this->templateVariableContainer
    ** !!! the view is not in $this->variableContainer anymore. Currently there is no way to fetch the View from a ViewHelper.
    ** Introduced a new $this->controllerContext containing the context variables of the controller
    ** !!! The request can be now found in $this->controllerContext->getRequest()
    ** !!! The URIHelper has been renamed to URIBuilder and can be now found in $this->controllerContext->getURIBuilder()
    ** Introduced a new ViewHelperVariableContainer, available in $this->viewHelperVariableContainer to pass data between ViewHelpers. Should only be needed in very rare cases.
    ** !!! Removed <f:format.htmlEscape> ViewHelper! Please remove these declarations in your template! Escaping of object accessors is now automatically done, see next point.
    * !!! ObjectAccessors {...} are now automatically HTMLspecialChar'd if not used as an argument to a ViewHelper. This is done using a new ObjectAccessorPostProcessor. Lateron, this will be made configurable.

commit a737739af5637ab6b5a19cfd7eb41d646b4c020c
Author: Bastian Waidelich <*****@typo3.org>
Date:   Thu Sep 17 12:44:23 2009 +0000

    [+FEATURE] Fluid (Viewhelpers): Added backend mode support for view helpers base, cObject, format.crop (partly), link.email, translate (partly), uri.email. Now only image- and renderFlashMessages view helpers are not working in BE

commit ec01954be8d0a2d1193facb2deee158176d5c1c7
Author: Bastian Waidelich <*****@typo3.org>
Date:   Wed Sep 23 20:47:14 2009 +0000

    [~BUGFIX] Fluid (ViewHelpers): fixed and tweaked format.crop view helper (BE mode)
    [-TASK] Fluid (ViewHelpers): removed instanceof check from be.menus.actionMenu view helper to enable wrapping of menuItems in <f:if> blocks

commit dcae0299252d6c14156834d409b8f1d3a71df87b
Author: Sebastian Kurfürst <*****@typo3.org>
Date:   Wed Nov 11 14:51:34 2009 +0000

    [+BUGFIX] Fluid (ViewHelpers): Removed newline at beginning of Crop ViewHelper, in front of <?php

commit 96ca102935d2d75ee215a830ee8f39815cc6fc4c
Author: Felix Oertel <*****@foertel.com>
Date:   Tue Jun 1 12:36:53 2010 +0000

    [+BUGFIX] Fluid (ViewHelpers): added auto-detection of string-format and propper cropping of HTML. Resolves #7743

commit 9100dbf5e3d05a8ef83d607f5d9b46f8097a68d4
Author: Bastian Waidelich <*****@typo3.org>
Date:   Mon Jul 12 13:55:21 2010 +0000

    [+FEATURE] Fluid (ViewHelpers): format.crop ViewHelper now supports all features in Backend mode. Relates to #8648

commit 186bdaeac89820779f91853b830cc95d60c7ad58
Author: Bastian Waidelich <*****@typo3.org>
Date:   Tue Jul 13 09:42:26 2010 +0000

    [-TASK] Fluid: R*****@version annotation from all Fluid classes to ease the backporting process. Relates to #8835 (backported from Fluid package)

commit 1d36de6ed90007e324b773782e8f0a1d1c1191a2
Author: Bastian Waidelich <*****@typo3.org>
Date:   Tue Jul 13 10:12:30 2010 +0000

    [-TASK] Fluid: R*****@package/@subpackage annotations from all Fluid classes. They have already been removed in FLOW3 packages in r2813.

commit 7c4adb435f5739a8574b3c28d79993ec1cae4270
Author: Bastian Waidelich <*****@typo3.org>
Date:   Mon Jul 19 18:09:46 2010 +0000

    [~TASK] Fluid (ViewHelpers): Fixed BE support of the ViewHelpers cObject, format.crop, uri.resource. Relates to #8947
    [~TASK] Fluid (ViewHelpers): Added BE support in the ViewHelpers format.html and image. Relates to #8947

commit 902aa6ba6e2e57c1d9da465ddb12613d109da4a7
Author: Sebastian Kurfürst <*****@typo3.org>
Date:   Tue Nov 2 13:24:45 2010 +0000

    [+BUGFIX] Fluid: Adjust Fluid to Dependency Injection changes
    
    Relates to: #9062

commit 5c8c4d6012158d52bf1618cb25ef066d9f639f31
Author: Bastian Waidelich <*****@typo3.org>
Date:   Sun Nov 14 13:38:48 2010 +0000

    [+FEATURE] Fluid (Core/Widget): Added Tx_Fluid_Core_Widget_Bootstrap that is used to dispatch Ajax requests (see ext_typoscript_setup.txt).
    [~TASK] Fluid (Compatibility): Removed Tx_Fluid_Compatibility_ObjectManager and replaced instances by Tx_Extbase_Object_ObjectManagerInterface instances
    [~TASK] Fluid (Core/Widget): AbstractWidgetController has to be a singleton so it can be injected in the WidgetViewHelper.. To be discussed!
    [+TASK] Fluid (Core/Widget): AjaxWidgetContextHolder is now correctly stored in the BE/FE Users session if the ajaxWidget of the corresponding Widget is TRUE.
    [+TASK] Fluid (Core/Widget): The WidgetContext now contains a reference to the parent extension & plugin name. That's needed for the widgetAjaxResponse.
    [+BUGFIX] Fluid (Core/Widget): WidgetRequestBuilder now correctly interprets GET parameters and dispatches Ajax requests
    [+BUGFIX] Fluid (ViewHelpers): Modified ViewHelpers cObject, format.crop, format.html, image, uri.image so that they use dependency injection in order to retrieve the current cObject instance from the configurationManager
    [+BUGFIX] Fluid (ViewHelpers): Fixed form ViewHelper to respect configured pluginNamespace in field name prefixes
    [+BUGFIX] Fluid (ViewHelpers): link.widget/uri.widget ViewHelpers now create correct URIs
    [+BUGFIX] Fluid (ViewHelpers):*****@inject annotation by injectController method in AutocompleteViewHelper.

commit 472451987ca0530fa5828bb0b79fcafa2f905a35
Author: Bastian Waidelich <*****@typo3.org>
Date:   Fri Nov 19 20:58:09 2010 +0000

    [-TASK] Fluid: R*****@scope annotations as they are not used in v4

commit dd8928aed4c119d8db37322acb91ded24ba5cc35
Author: Bastian Waidelich <*****@typo3.org>
Date:   Thu Dec 30 16:21:11 2010 +0000

    [+TASK] Fluid (ViewHelpers): Fix, cleanup and extend inline documentation of ViewHelpers
    
    Resolves #10908

commit fd09d197fa8886b97cb20aa9573f39cd08ce989e
Author: Bastian Waidelich <*****@typo3.org>
Date:   Thu Nov 10 18:27:58 2011 +0100

    [TASK] S*****@author annotations
    
    This backports three recent changes of the TYPO3.Fluid package:
    - R*****@license annotation from files (290f4f5)
    - Simplify license header in PHP files (14bacba)
    - D*****@author tags from source code (9c2e837)
    
    This should not contain any functional change!
    
    Change-Id: I9376dca4af78c4f0f82413011d115b8ad04634dd

commit ca40f8a066da4ea3c849d74f68a9bc73758976c5
Author: dkd-egerer Sascha Egerer <*****@dkd.de>
Date:   Sat Apr 14 21:43:10 2012 +0200

    [TASK] Remove trailing whitespace
    
    There must be no empty lines after the closing
    PHP tag. Empty lines after closing tags break
    output compression in PHP and/or result in AJAX
    errors.
    
    Change-Id: I0484ca29d8134d0828cf30880d5aafd43ed9d78e
    Resolves: #36076
    Releases: 6.0
    Reviewed-on: http://review.typo3.org/10499
    Reviewed-by: Ingo Pfennigstorf
    Tested-by: Ingo Pfennigstorf
    Reviewed-by: Daniel Lorenz
    Tested-by: Daniel Lorenz
    Reviewed-by: Christian Kuhn
    Tested-by: Christian Kuhn

commit ec3891d8d4e339d8319428211207e6201be9fd73
Author: Thomas Maroschik <*****@dfau.de>
Date:   Wed Oct 17 21:18:26 2012 +0200

    [TASK][WIP] Move non class code back to source files
    
    Change-Id: I620d2e61860142cdc89cc83474c95542799961c0

commit 554e8f890dcc0dd86a27518b58e2b54be26fd37e
Author: Thomas Maroschik <*****@dfau.de>
Date:   Wed Oct 17 22:20:17 2012 +0200

    [TASK] Namespace classes
    
    Change-Id: Ia7432e1c923826ed58206bca15fb94509adbd508

commit 547ef7f60f39c6bfcb0376e5e76070da85860098
Author: Arvid Jakobsson <*****@gmail.com>
Date:   Mon Sep 17 21:25:51 2012 +0200

    [TASK] Remove superfluous parenthesis in sysexts
    
    Superfluous brackets in fluid after namespaces move
    Change ("a" . "b") . "c" into "a" . "b" . "c" using the lex-pass tool.
    
    Resolves: #41016
    Related: #40095
    Releases: 6.0
    Change-Id: I64741473cb24eda343f0576ebd1a0f1846dfc3f8
    Reviewed-on: http://review.typo3.org/14675
    Reviewed-by: Oliver Hader
    Tested-by: Oliver Hader

commit 9d46e6932d35c79bf87c96fa38b8e537c4192f23
Author: Alexander Schnitzler <*****@typovision.de>
Date:   Tue Nov 20 16:27:02 2012 +0100

    [CLEANUP] Adjust code to CGL and fix small namespace bugs
    
    * whitespaces, tabs and blank line issues
    * bool -> boolean
    * int -> integer
    * fix wrong namespace annotations
    
    Fixes: #43157
    Releases: 6.0
    Change-Id: I8397948e19248db029d8efd1555ee56e4982742d
    Reviewed-on: http://review.typo3.org/16619
    Reviewed-by: Helmut Hummel
    Tested-by: Helmut Hummel

commit fae04a024687fd061c41d67076cfb455d189aefc
Author: Christian Kuhn <*****@schwarzbu.ch>
Date:   Wed May 1 17:57:52 2013 +0200

    [BUGFIX] Mentions of old class names
    
    Change-Id: Iee7a863a9d68d1379e1e616414b9848e0c535a8a
    Resolves: #47791
    Releases: 6.2
    Reviewed-on: https://review.typo3.org/20378
    Reviewed-by: Christian Kuhn
    Tested-by: Christian Kuhn

commit 2332335a3239aef82add5ed3354cc99c715292cf
Author: Christian Kuhn <*****@schwarzbu.ch>
Date:   Fri Jun 21 23:55:24 2013 +0200

    [TASK] Remove last bits of forceCharset handling
    
    Core version 4.5 introduced UTF8 only for charset conversion, and
    accepted a fallback under special circumstances. The fallback was
    removed with 4.7.
    This setting is now finally fully removed from the configuration
    and not taken into account anymore.
    
    Change-Id: Ic347c3decb985ec63eb499d5d75827fc7f1f7a8a
    Resolves: #49336
    Related: #49299
    Related: #34092
    Releases: 6.2
    Reviewed-on: https://review.typo3.org/21584
    Reviewed-by: Markus Klein
    Reviewed-by: Philipp Gampe
    Tested-by: Philipp Gampe
    Reviewed-by: Anja Leichsenring
    Tested-by: Anja Leichsenring
    Reviewed-by: Christian Kuhn
    Tested-by: Christian Kuhn

commit 77f29a3c69a7cbb27b34072754aa503bace6c9f1
Author: Christian Kuhn <*****@schwarzbu.ch>
Date:   Tue Oct 1 14:40:56 2013 +0200

    [TASK] Remove closing PHP tags
    
    Change-Id: Iaa92566c53301e49396fc9fb26b0b339c48d567b
    Resolves: #52360
    Releases: 6.2
    Reviewed-on: https://review.typo3.org/24212
    Reviewed-by: Christian Kuhn
    Tested-by: Christian Kuhn
    Reviewed-by: Ernesto Baschny
    Tested-by: Ernesto Baschny
    Reviewed-by: Anja Leichsenring
    Tested-by: Anja Leichsenring