# Solved: How I can create a dynamic menu in tinyMCE 4.x?



## blaherrod (Jan 31, 2013)

How I can create a dynamic menu?
with the following structure:
menu
menu item 1
menu item 1.1
menu item 1.2
menu item 2
menu item 2.1
menu item 2.2
I saw an example com fiddle but the tinymce 3.5.8 and does not apply to the version 4
I found a tiny example but for 3.x and modify

```
tinymce.create('tinymce.plugins.ExamplePlugin', {
        createControl: function(n, cm) {
                switch (n) {
                        case 'mymenubutton':
                                var c = cm.createMenuButton('mymenubutton', {
                                        title : 'My menu button',
                                	image : '/example_data/example.gif',
                                        icons : false
                                });

                                c.onRenderMenu.add(function(c, m) {
                                        var sub;
                                        for(i=1;i<=3;i++)
                                        {
                                            sub = m.addMenu({title:'Item '+ i});
                                            for(j = 1; j <= 4; j++)
                                            {
                                                sub.add({title:'subItem' + j, onclick : function(){
                                                tinyMCE.activeEditor.execCommand('mceInsertContent', false, i+'this is sub_item -> '+j);
                                                }});
                                            }
                                        }
                                });
                                      
                                // Return the new menu button instance
                                return c;
                }

                return null;
        }
});

// Register plugin with a short name
tinymce.PluginManager.add('example', tinymce.plugins.ExamplePlugin);
```
I want to know how tiny would do something similar for 4.x


----------



## colinsp (Sep 5, 2007)

You need to give a bit more information.

Why do you want to use tinyMCE for this? In what context do you want this menu? Your own HTML, Wordpress Joomla or what? Why can't you code this in your site?


----------



## juliushouston (Jul 9, 2013)

Yes, I dont think its that much difficult but ya need more info as mentioned above. argentinos


----------



## blaherrod (Jan 31, 2013)

hello, thank you very much.
Answering questions:
1. - Because I am developing my own CMS and I need to post news, and I want to insert a keyword and then the keyword I'm going to parse
2.-I want to add in the menu bar.
Three. - If my own html code.

Already solved, take me all day , build the menu and add it to the menubar, and now I have another question that is how to generate a json formatted accordance with mysql and php query and give me the result:
var arrayJson=[
{title:'item 1', items:[
{title:'subitem1.1', keyword:'{'+parte1+parte2+parte3+'}' },
{title:'subitem1.2', keyword:'{'+parte1+parte2+parte3+'}' }
]},
{title:'item 2', items:[
{title:'subitem2.1', keyword:'{'+parte1+parte2+parte3+'}' },
{title:'subitem2.2', keyword:'{'+parte1+parte2+parte3+'}' }
]},
{title:'item 3', items:[
{title:'subitem3.1', keyword:'{'+parte1+parte2+parte3+'}' },
{title:'subitem3.2', keyword:'{'+parte1+parte2+parte3+'}' }
]}
];
considering that the titles are part of the query and the keyword was formed three fields in a query log
considering that the titles are a query field and the keyword was formed three fields in a record of the query.
possible result of the query.
id | nombre | parte2 | parte3 
1 item1 gal1 conf1
1 item1 gal2 conf2
2 item2 gal4 conf5
2 item2 gal2 conf7
...
sorry
(translated with google)


----------

