0

Using TYPO3 8 LTS, we got many standardized filenames like:

ABC_105-Report.pdf 
DEFGH_110-Brochure.ppt

We need to remove whatever is at left of "-" so it becomes a list like this in TYPO3 Frontend:

Report.pdf 
Brochure.ppt

We are already using VHS Viewhelpers which contains Format:Eliminiate, Substring so it may be part of the solution.

Peter Kraume
  • 3,577
  • 2
  • 21
  • 39

2 Answers2

3

One possible solution is VHS: Format / PregReplaceViewHelper.

<f:alias map="{filenames: {
    0: 'ABC_105-Report.pdf',
    1: 'DEFGH_110-Brochure.ppt',
    2: 'FilenameWithoutMagicChar.jpg',
    3: 'Multiple-Magic-Chars.jpg'}}">
    <ul>
        <f:for each="{filenames}" as="filename">
            <li>
                {v:format.pregReplace(
                    subject: filename, 
                    pattern: '/^[^-]*-/', 
                    replacement: ''
                )}
            </li>
        </f:for>
    </ul>
</f:alias>

Result:

  • Report.pdf
  • Brochure.ppt
  • FilenameWithoutMagicChar.jpg
  • Magic-Chars.jpg

If 'Chars.jpg' is required instead of 'Magic-Chars.jpg', the regular expression is /-.*/.

1

a very basic typoscript viewhelper:

in fluid:

<f:cObject typoscriptObjectPath="lib.filenameStub" data="{filename}" />

in typoscript:

lib.filenameStub = TEXT
lib.filenameStub {
    current = 1
    split {
        max = 2
        token = -
        returnKey = 1
    }
}
Bernd Wilke πφ
  • 10,390
  • 1
  • 19
  • 38