We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 16680
    • 73 Posts
    Hi all,

    So lets say I would like to give a user the possibility to choose an image for his weblink.


    I would then create a TV called ’ImageDisplay’, and use the @DIRECTORY binding to load in all the images:


    Ok, so far so good. Now I have a list of all the images and the option to choose one.

    But... I would like to display the images in the directory as images instead of just file names:


    How can I do that in a clever way? I guess I could go into the core and just put a wrapper <img> tag around the ’radio option’ code, but hacking the cores is bad I guess:
    Here is the code from manager/includes/tmplvars.inc.php line 123 and on:
    			case "option": // handles radio buttons
    				$index_list = ParseIntputOptions(ProcessTVCommand($field_elements, $field_name));
    				while (list($item, $itemvalue) = each ($index_list))
    				{
    					list($item,$itemvalue) =  (is_array($itemvalue)) ? $itemvalue : explode("==",$itemvalue);
    					if (strlen($itemvalue)==0) $itemvalue = $item;
    					$field_html .=  '<input type="radio" value="'.htmlspecialchars($itemvalue).'" name="tv'.$field_name.'" '.($itemvalue==$field_value ?'checked="checked"':'').' onchange="documentDirty=true;" />'.$item.'<br />';
    				}
    				break;
    


    I guess perhaps I could even duplicate that whole block, and create my own ’view’. But then again, hacking the core is bad right?

    I know that I could just use ’image’ instead of ’radio option’ as ’Input Type’ in my TV, but giving the user the cance to directly click on an image seems more appealing to me.


    .larsb
      Signature on it&#39;s way
      • 33337
      • 3,975 Posts
      You can write a plugin which changes the manager interface on the fly, please see ManagerManager how it works. So you can inject the <img> tag without hacking the core.
        Zaigham R - MODX Professional | Skype | Email | Twitter

        Digging the interwebs for #MODX gems and bringing it to you. modx.link
        • 20413
        • 2,877 Posts
        If place the icons folder inside assets/images/
        and set the TV with Input Type: Image and Default Value: assets/images/icons/your_default_icon.jpg

        The image can be easily changed with the Resource Browser (FCKEditor) defaults to assets/images.
        and then call your pics with <img src="[*YourImageTV*]" alt="[*YourAltTV*]" />
          @hawproductions | http://mrhaw.com/

          Infograph: MODX Advanced Install in 7 steps:
          http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

          Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
          http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower
          • 16680
          • 73 Posts
          @zi - thanks for your answer. I will have a look at managermanager

          @mrchaw - not sure I understand your answer completely. I will try Zi’s suggestion first, then maybe return for more detail.

          Thanks

          .larsb
            Signature on it&#39;s way