Search code examples
typo3fluid

How to split a filename into different parts with VHS in TYPO3


After getting a filename from a folder I would like to split it into parts to show the parts in the Fluid-template.

Filename: My-super-song_My-Name_1.1.2019.mp3

Should be formatted to HTML like this:

<span>My super song</span> recorded by <span>My name</span> at <span>1.1.2019</span>

I use a VHS view helper to remove the .mp3 of the file:

<v:format.replace substring=".mp3" content="{file.name}" replacement="" count="123"></v:format.replace>

Is there any view helper in VHS that could achieve the splitting? Many thanks in advance!


Solution

  • Thanks to Mathias Brodola here is the code that is working, many thanks!

    <v:iterator.explode content="{file.name}" glue="_" as="song">
        <!-- Shows all exploded strings for testing purposes
        <f:for each="{song}" as="iter">
            <pre>{iter}</pre>
        </f:for>
        -->
        <h2>{song.0}</h2>
        <p>Date: 
            <v:format.replace substring=".mp3" content="{song.1}" replacement=""></v:format.replace></p>
    </v:iterator.explode>