Top level menu items as images


https://forum.kartris.com/Topic535.aspx
Print Topic | Close Window

By saturation - Tue 3 May 2011
Does anyone have any advice or suggestions on how to use images instead of text as the top level menus?
By Mohammad - Wed 4 May 2011
If you are using Kartris v1.3 (because the code is partially opened) then you can apply the below:

1. Go to UserControls > Skin > CategoryMenu.ascx.vb
2. Add the following lines as last lines of the 'menCategory_MenuItemDataBound' event (just before End Sub):
Dim strImagePath As String = GetImagePath(CType(e.Item.DataItem, SiteMapNode).Key)
If strImagePath IsNot Nothing Then
  e.Item.ImageUrl = strImagePath
  e.Item.Text = ""
End If

3. Add the following function in the same page:
Function GetImagePath(ByVal strKey As String) As String
Dim arrKeys() As String = strKey.Split(",")
If arrKeys.Length > 2 Then Return Nothing
Dim strFolderPath As String = _
Kartris.CkartrisImages.strCategoryImagesPath & "/" & arrKeys(1) & "/"
If Not Directory.Exists(Server.MapPath(strFolderPath)) Then Return Nothing
Dim dirFolder As New DirectoryInfo(Server.MapPath(strFolderPath))
If dirFolder.GetFiles().Length < 1 Then Return Nothing
Return CkartrisBLL.WebShopURL & "Image.aspx?strFileName=" & dirFolder.GetFiles()(0).Name & _
"&amp;strItemType=c&amp;numMaxHeight=" & _
KartSettingsManager.GetKartConfig("frontend.display.images.minithumb.height") & _
"&amp;numMaxWidth=" & _
KartSettingsManager.GetKartConfig("frontend.display.images.minithumb.width") & _
"&amp;numItem=" & arrKeys(1) & "&amp;strParent=0"
End Function

Above code, will show the image of the category (if its top level one) and removes the name of the category.

If the image(s) didn't appear, you need to wait for a while or restart the application, cause the category menu is using the output cache.