I'm creating a custom module which displays Google Maps in the frontend of Magento. To get those maps the Admin would have to enter and save the URL of the map location in the Admin Panel. This all works fine. The URL is being saved in the database and the maps are displayed in the frontend of the store.
But now I would like to display a preview of this map in the Admin Panel too. This will allow the Admin to easily check whether the correct URL is entered and saved.
I want to display this Preview Map
in a new <field>
(just below the field where the URL should be entered) and use a Map Preview <label>
. The mockup below displays what I am trying to achieve.
To my modules system.xml
file I have added the following code:
<fields>
....
<preview translate="label comment">
<label>Map Preview</label>
<frontend_type>link</frontend_type>
<frontend_model>mymodule/system_config_map</frontend_model>
<comment>Preview of your map</comment>
<sort_order>20</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</preview>
</fields>
And my MyNamespace/MyModule/Block/System/Config/Map.php
contains the following code:
class MyNamespace_MyModule_Block_System_Config_Map extends Mage_Adminhtml_Block_Abstract implements Varien_Data_Form_Element_Renderer_Interface
{
public function render(Varien_Data_Form_Element_Abstract $element) {
$url = Mage::helper('mymodule')->getMapUrl($store = null);
return '<iframe style="border: 0;" src="'.$url.'" frameborder="0" width="100%" height="270"></iframe>';
}
}
This does render the Google Map in the Admin Panel and it also renders in the proper <group>
but it is not loaded in the <field>
that I want. This is an actual screen shot of the current situation.
I have tried every <frontend_type>
I can think of....
So my question is: How can I insert an <iframe>
in an Admin Panel <field>
? Should I add something to my <frontend_model>
?
<frontend_model>
is indeed the way to go. Within that file you should be able to$rendered .= '<iframe...
sort_order
of your'Map Details'
field? Is it less than the20
used for your'Map Preview'
?