TYPO3: Icon for Menu from page's media files

Add the following typoscript to get the icon for menu, from its page's media files options.

 

lib.menu = HMENU
lib.menu {
    entryLevel = 1
    expAll = 1
    1 = TMENU
    1{
        wrap = <ul class="leftmenu"> | </ul>
        expAll = 1
        NO = 1
        NO{
            before.wrap = <li>|
            stdWrap.cObject = COA
            stdWrap.cObject {
                10 = FILES
                10 {
                    # Get the images related to the current page
                    references {
                        table = pages
                        fieldName = media
                    }
                # Render each image and wrap it as appropriate
                    renderObj = TEXT
                    renderObj {
                        typolink {
                            parameter.data = file:current:publicUrl
                            forceAbsoluteUrl = 1
                            returnLast = url
                        }
                        wrap = |,
                    }
                    stdWrap {
                    # Take only the first image if several are defined
                    listNum = 0
                    # Use default image if none is available
                        ifEmpty.cObject = TEXT
                        ifEmpty.cObject.typolink {
                            parameter = path_to_images/logo.png
                            forceAbsoluteUrl = 1
                            returnLast = url
                        }
                        wrap = <img src="|" title="image" />
                    }
                }

                20 = TEXT
                20.field = title
                20.wrap = <span>|</span>
            }
            after.wrap = |</li>
        }
        ACT < .NO
        ACT.before.wrap = <li class="active"> |

        CUR < .NO
        CUR.before.wrap = <li class="active"> |
    }
}