Magento – Understanding Dynamic Widget Parameters

widgets

Is there a way to add dynamic parameter options to a widget?

For example, I know the tutorial here tells you you can set up parameters like this in your widget.xml file:

<?xml version="1.0"?>
<widgets>
<some_unique_widget_name type="block_group/block_path" translate="name description" module="modulename">
    <name>Widget name</name>
    <description>Short widget description</description>
    <parameters>
        <first_option translate="label">
            <!-- General option properties -->

            <!-- Defines if the option is allowed to be empty -->
            <required>1</required>
            ... etc ...

But in my situation, I'd like the parameters to vary based on database values.

Is this possible? Or is there another solution? Or am I looking at this the wrong way entirely?

Thank you.

Best Answer

In hindsight, I didn't ask my question very well because I didn't know what I was really looking for. Hopefully this helps someone.

Ultimately, I went for a setup like this:

    <parameters>                                              
        <report_id type="complex" translate="label">          
            <visible>1</visible>                              
            <required>1</required>                            
            <label>Report</label>                             
            <type>label</type>                                
            <helper_block>                                    
                <type>foobar_sqlreport/sqlreport</type>     
                <data>                                        
                    <button translate="open">                 
                        <open>Select Report...</open>         
                    </button>                                 
                </data>                                       
            </helper_block>                                   
            <sort_order>10</sort_order>                       
        </report_id>                                             
    </parameters>                                             

The key to this is the helper_block section, which dynamically loads all my reports from the database. I used the CMS Static Block as a template for creating my own widget settings. You can find a tutorial on how to do that here.

Related Topic