We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 31471
    • 206 Posts
    Hi,
    I want to list my Icons TV in a custom Listbox, similar to Listbox (Single-Select), with a slight difference that the list-items get a css style "display:inline-block;".
    So I made a copy of files listbox.class.php and listbox-single.tpl, and started to do the changes.

    In listbox-icons.class.php I gave the class a different name and point it to my own template file. No other differences, and it does the job:
    class modTemplateVarInputRenderIconsListbox extends modTemplateVarInputRender {
        public function getTemplate() {
            return $this->modx->getOption('core_path').'components/icontv/tv/input/tpl/listbox-icons.tpl';
        }
        public function process($value,array $params = array()) {
            $options = $this->getInputOptions();
            $items = array();
    
            foreach ($options as $option) {
                $opt = explode("==",$option);
                if (!isset($opt[1])) $opt[1] = $opt[0];
                $items[] = array(
                    'text' => htmlspecialchars($opt[0],ENT_COMPAT,'UTF-8'),
                    'value' => htmlspecialchars($opt[1],ENT_COMPAT,'UTF-8'),
                    'selected' => strcmp($opt[1],$value) == 0,
                );
            }
            $this->setPlaceholder('opts',$items);
        }
    }
    return 'modTemplateVarInputRenderIconsListbox';


    In listbox-icons.tpl I only add a line with my own template code:
    <select id="tv{$tv->id}" name="tv{$tv->id}">
    {foreach from=$opts item=item}
    	<option value="{$item.value}" {if $item.selected} selected="selected"{/if}>{$item.text}</option>
    {/foreach}
    </select>
    
    <script type="text/javascript">
    // <![CDATA[
    {literal}
    Ext.onReady(function() {
        var fld = MODx.load({
        {/literal}
            xtype: 'combo'
            ,transform: 'tv{$tv->id}'
            ,id: 'tv{$tv->id}'
            ,triggerAction: 'all'
            ,width: 400
            ,allowBlank: {if $params.allowBlank == 1 || $params.allowBlank == 'true'}true{else}false{/if}
            ,tpl: new Ext.XTemplate(
                '<tpl for="."><div class="x-combo-list-item" style="display:inline-block;">'
                ,'{text}'
                ,'</div></tpl>')
    
            {if $params.title},title: '{$params.title}'{/if}
            {if $params.listWidth},listWidth: {$params.listWidth}{/if}
            ,maxHeight: {if $params.maxHeight}{$params.maxHeight}{else}300{/if}
            {if $params.typeAhead}
                ,typeAhead: true
                ,typeAheadDelay: {if $params.typeAheadDelay && $params.typeAheadDelay != ''}{$params.typeAheadDelay}{else}250{/if}
            {else}
                ,editable: false
                ,typeAhead: false
            {/if}
            {if $params.listEmptyText}
                ,listEmptyText: '{$params.listEmptyText}'
            {/if}
            ,forceSelection: {if $params.forceSelection && $params.forceSelection != 'false'}true{else}false{/if}
            ,msgTarget: 'under'
    
        {literal}
            ,listeners: { 'select': { fn:MODx.fireResourceFormChange, scope:this}}
        });
        Ext.getCmp('modx-panel-resource').getForm().add(fld);
    });
    {/literal}
    // ]]>
    </script>
    


    Now the Error Message is this:
    Fatal error: Uncaught exception 'SmartyCompilerException' with message 'Syntax Error in template "****/public_html/core/components/icontv/tv/input/tpl/listbox-icons.tpl" on line 21 " ,'{text}'" unknown tag "text"'

    My debugging experience is that, without {text} tag, the <select><option> html tags are populated and the dropdown list is swoing with the right amount of empty lines.

    I think I just miss something to tell Smarty the {text} tag.

    Any suggestions please?
      • 3749
      • 24,544 Posts
      I think you want

      $items = array(


      instead of

      $items[] = array(
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 31471
        • 206 Posts
        No, inside a foreach it's ok like that.
        And again, this is a copy of the original files of MODX's Listbox (Single-Select) input type. I just added this line:
        ,tpl: new Ext.XTemplate(
                    '<tpl for="."><div class="x-combo-list-item" style="display:inline-block;">'
                    ,'{text}'
                    ,'</div></tpl>')

          • 3749
          • 24,544 Posts
          It just looked wrong to me. wink

          It's sending setPlaceholder() (which is outside the loop) an array of arrays for the value of a single placeholder, though the docs do list 'mixed' for the type of that argument. You're right, though, it's that way in the core code. I've just never used it that way.
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 31471
            • 206 Posts
            {literal}
                    ,tpl: new Ext.XTemplate(
                      '<tpl for="."><div class="x-combo-list-item" style="display:inline-block;">'
                        ,'{text}'
                        ,'</div></tpl>')
            {/literal}

            It's that simple!