WebsiteBaker Support (2.8.x) > Templates, Menus & Design

menu with images?

(1/2) > >>

Roych:
Hello,
I'm trying to get images to my menu (flags) and I did so with a simple code, but the problem is that if there is no image in folder it shows me a litle no-image placeholder is it possible to get rid of this so that if there is no image it shows normal?


My code now is:

--- Code: ---
<?php
show_menu2(
        $aMenu          = 0,
        $aStart         = SM2_ROOT+1,
        $aMaxLevel      = SM2_ALL,
        $aOptions       = SM2_ALL|SM2_PRETTY,
        $aItemOpen      = '<li class="[class] [if(class==menu-current){active}] [if(class==menu-expand){dropdown}]">[a]<div class="zastavice"><img src="http://riskchange.eu/site/templates/risk/menu_images/[menu_title].png" class="zastavice2"/><>[menu_title]</a>',
        $aItemClose     = '</li>',
        $aMenuOpen      = '<ul>',
        $aMenuClose     = '</ul>',
        $aTopItemOpen   = false,
        $aTopMenuOpen   = '<ul class="sf-menu">'
    ); ?>

--- End code ---


Or is there any better way to do this?


Thank you very much
R

marmot:
Hi,


--- Quote from: Roych on July 16, 2016, 03:16:32 PM ---... if there is no image in folder it shows me a litle no-image placeholder is it possible to get rid of this so that if there is no image it shows normal?
--- End quote ---
I'm afraid showmenu can't do that. I guess the most easy thing would be to add blank images named by the menu title if there is no menu image available.

You can also patch showmenu2 to be more clever at this problem.
Or you can do some general replacement for all broken image links on a page by javascript, droplet or output filter.
For example if query is active on your page you can use

--- Code: ---$("img").error(function(){
        $(this).hide();
});
--- End code ---

regards

jacobi22:
stackoverflow is your friend...

somewhere in the template-index.php a javascript-function like

define here your no-image-file (maybe a transparent gif with the same width&height?)

--- Code: ---<script type="text/javascript">
function imgError(image) {
    image.onerror = '';
    image.src = TEMPLATE_DIR+'/menu_images/no_image.png';
    return true;
}
</script>
--- End code ---

in the img-tag from $aItemOpen set a onerror like


--- Quote ---$aItemOpen      = '<li class="[class] [if(class==menu-current){active}] [if(class==menu-expand){dropdown}]">[a]<div class="zastavice"><img src="http://riskchange.eu/site/templates/risk/menu_images/[menu_title].png" onerror="imgError(this);" class="zastavice2"/><>[menu_title]</a>',
--- End quote ---

it works fine, but in produce a network-error, because the show_menu2 calls also a missing image like a icon for page xyz, if there is no icon in the folder
                

Roych:

--- Quote from: jacobi22 on July 17, 2016, 02:24:43 AM ---stackoverflow is your friend...

somewhere in the template-index.php a javascript-function like

define here your no-image-file (maybe a transparent gif with the same width&height?)

--- Code: ---<script type="text/javascript">
function imgError(image) {
    image.onerror = '';
    image.src = TEMPLATE_DIR+'/menu_images/no_image.png';
    return true;
}
</script>
--- End code ---

in the img-tag from $aItemOpen set a onerror like


--- Quote ---$aItemOpen      = '<li class="[class] [if(class==menu-current){active}] [if(class==menu-expand){dropdown}]">[a]<div class="zastavice"><img src="http://riskchange.eu/site/templates/risk/menu_images/[menu_title].png" onerror="imgError(this);" class="zastavice2"/><>[menu_title]</a>',
--- End quote ---

it works fine, but in produce a network-error, because the show_menu2 calls also a missing image like a icon for page xyz, if there is no icon in the folder
               

--- End quote ---


Great one, works great, is there any way to get rid of this error maybe? It's not really a problem but, it's an error ...  ;D

jacobi22:

--- Quote ---Great one, works great, is there any way to get rid of this error maybe? It's not really a problem but, it's an error ...
--- End quote ---

the answer is very easy: dont produce an error ;-)
from my point its not possible to set a "standard picture" (without an error) inside of the show_menu2 without a lot of changes in the include.php and in the core

Navigation

[0] Message Index

[#] Next page

Go to full version