Not logged in. · Lost password · Register
Forum: General Help and Support Development RSS
templates and the new menu-system
Avatar
meanddokuwiki #1
Member since Nov 2018 · 1 post
Group memberships: Members
Show profile · Link to this post
Subject: templates and the new menu-system
Hello,
I need some help with template and the new menusystem. I searched in the forum but couldn´t find find an answer. Even actual templates (besides the dokuwiki-template) use the old  tpl_ functions …
The dokuwiki-template uses the the following code for the page-actions menu:

<!-- PAGE ACTIONS -->
            <div id="dokuwiki__pagetools">
                <h3 class="a11y"><?php echo $lang['page_tools']; ?></h3>
                <div class="tools">
                    <ul>
                        <?php echo (new \dokuwiki\Menu\PageMenu())->getListItems(); ?>
                    </ul>
                </div>
            </div>

Ok. Now I want to add a new but existing menuitem/button to it, lets say the Media-manager. The former way was to use the tpl_ … functions:

<!-- PAGE ACTIONS -->
            <div id="dokuwiki__pagetools">
                <h3 class="a11y"><?php echo $lang['page_tools']; ?></h3>
                <div class="tools">
                    <ul>
                        <?php echo (new \dokuwiki\Menu\PageMenu())->getListItems(); ?>

<?php tpl_toolsevent('usertools', array(                                 'media'     => tpl_action('media', 1, 'li', 1,'<span>', '</span> <img src='.tpl_basedir().'images/pagetools/11_mediamanager.png width="35px" height="35px" ')
)); ?>

                    </ul>
                </div>
            </div>

It is working ok right now, but it gives a warning that its depreceated. How this is done in the new menusystem? Do I need to write a plugin for that or can it be achieved with a template only?

Thanks for any hints
Avatar
schplurtz (Moderator) #2
Member since Nov 2009 · 498 posts · Location: France, Finistère
Group memberships: Global Moderators, Members
Show profile · Link to this post
Hi,

As you've already discovered, not all templates (very few ?) currently use this new menusystem. We can only hope that actively maintained templates will switch to this system. So, depending on your template, you have to edit the template files or use the menu system.

It is working ok right now, but it gives a warning that its depreceated. How this is done in the new menusystem? Do I need to write a plugin for that or can it be achieved with a template only?
With the menu system, you need to create an action plugin that handles the MENU_ITEMS_ASSEMBLY event. The upside is that you only have to do this once; when you update DokuWiki, your button will still be there.

If you've never written a plugin before, take a look at https://www.dokuwiki.org/devel:plugins, there is, among other things, a link to a plugin wizard that will create a skeleton code. The example links in the MENU_ITEMS_ASSEMBLY page are very helpful.
Avatar
andi (Administrator) #3
User title: splitbrain
Member since May 2006 · 3503 posts · Location: Berlin Germany
Group memberships: Administrators, Members
Show profile · Link to this post
As schplurtz said, if you want to modify menu contents you need to handle the appropriate action hook. However it is possible to do that from your template's code - no need to have a separate plugin. I recently implemented that in this template:

https://github.com/OpenSchulportfolio/dokuwiki-template-po…

Check the Template class and it's constructor for the hook registration.
Read this if you don't get any useful answers.
Lies dies wenn du keine hilfreichen Antworten bekommst.
Avatar
ach (Administrator) #4
Member since May 2006 · 1948 posts · Location: Folkestone, UK
Group memberships: Administrators, Members, Super Mods, Wiki Managers
Show profile · Link to this post
I planned to add the new menu system to the Starter template so that it's easier for others to start using it. But I gave up after a while as it was too difficult for me. I'm not sure if what I need to do is even possible.
If any volunteers want to make that change, I'd be very happy to review and merge it.
Avatar
Michaelsy #5
Member since Jun 2015 · 969 posts · Location: Düsseldorf, Germany
Group memberships: Members
Show profile · Link to this post
I have often noticed the term "new menu system". But I have nowhere found out what it actually is and what it is different from the "old menu system".

However, I have not yet collected the many small pieces of information that you may find in several places.
By Patreon.com a few eurons can be fed into the code phasers of
the DokuWiki engine. Besides, Andi's posts are worth reading.
Avatar
andi (Administrator) #6
User title: splitbrain
Member since May 2006 · 3503 posts · Location: Berlin Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Quote by Michaelsy:
I have often noticed the term "new menu system". But I have nowhere found out what it actually is and what it is different from the "old menu system".

My post at patreon should explain that well enough for template developers. End users probably do not need to think about it at all.

Quote by ach:
But I gave up after a while as it was too difficult for me. I'm not sure if what I need to do is even possible.

Can you explain what was difficult and what exactly you were trying to achieve? I would think that the starter template does not need to do anything different than what the dokuwiki template does.
Read this if you don't get any useful answers.
Lies dies wenn du keine hilfreichen Antworten bekommst.
Avatar
turnermm (Moderator) #7
Member since Oct 2009 · 4741 posts · Location: Canada
Group memberships: Global Moderators, Members, Super Mods
Show profile · Link to this post
As far as I can tell, the template author must use the pre-established menu types, and plugin authors must hook into one of these to enable a link or button.  But there seems to be no way for a template to register a new menu type, independent of site, user, page, or mobile.    If that's implicit here https://github.com/OpenSchulportfolio/dokuwiki-template-po…, then perhaps you could document that in the same way that events and plugins are documented.

In the old system, it was possible to place a link or set of links anywhere in the template using the TEMPLATE_<name>_DISPLAY hook.  I haven't found the equivalent for the new system.
Myron Turner
github: https://github.com/turnermm
plugins, templates: http://www.mturner.org/devel
This post was edited on 2019-04-17, 13:26 by turnermm.
Avatar
andi (Administrator) #8
User title: splitbrain
Member since May 2006 · 3503 posts · Location: Berlin Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Quote by turnermm:
As far as I can tell, the template author must use the pre-established menu types, and plugin authors must hook into one of these to enable a link or button.

Should use. By using the pre-established menu types, the template author ensures that plugins can easily hook into these menus without known any specifics of that template. Eg. the PDF export does not need to know how the bootstrap3 template integrates the link to export a page. It simply registers a MenuItem for the PageMenu.

Now, a template author could decide to do something fancy. Eg. Instead of having a single PageMenu, the author could decide to iterate over the items in that menu and split it into two sets of items: one set for known actions that should be prominently displayed and another for the rest.

Quote by turnermm:
But there seems to be no way for a template to register a new menu type, independent of site, user, page, or mobile.

They could. A template has it's own namespace. A template author could create a new Menu inheriting from AbstractMenu and put their own set of Items in it. The getItems() method in it would trigger a custom MENU_ITEMS_ASSEMBLY event with a new $view that plugin authors could use to target this specific template (how many plugin authors would do so is another question). This new custom defined Menu can be used by the template author just like any of the four predefined ones.

Quote by turnermm:
If that's implicit here https://github.com/OpenSchulportfolio/dokuwiki-template-po…, then perhaps you could document that in the same way that events and plugins are documented.

What this template does, is modifying the existing menus by basically implementing an action plugin component within the template it self. There is a lot else going on, but the basic gist is this:

  • define your own namespaced class in the template, just to encapsulate everything neatly (Template.php)
  • in that class' constructor register a new handler on the MENU_ITEMS_ASSEMBLY event (Template.php#L33)
  • define your own method handling that event, in this case we empty the menu for anonymous users, but we could also add our own MenuItems here Template.php#L78
  • ensure this new class is instantiated immediately when the template is loaded main.php (the same is in detail.php and mediamanager.php)

The same emchanism can be used to execute template code on nearly any DokuWiki event you want.

Quote by turnermm:
In the old system, it was possible to place a link or set of links anywhere in the template using the TEMPLATE_<name>_DISPLAY hook.

I'm not sure to which event you're referring to here. Do you mean TEMPLATE_PAGETOOLS_DISPLAY et al? That has been replaced by the four menu types. But yes, you can no longer emit arbitrary HTML in those. But doing so was probably bad style before as well.

Hope this clears stuff up a little. The how to trigger actions from Template code might be worth adding to the docs maybe.
Read this if you don't get any useful answers.
Lies dies wenn du keine hilfreichen Antworten bekommst.
Avatar
turnermm (Moderator) #9
Member since Oct 2009 · 4741 posts · Location: Canada
Group memberships: Global Moderators, Members, Super Mods
Show profile · Link to this post
I'll need some time to digest all of the info. in your post.

I'm not sure to which event you're referring to here
But on this point, just quickly:  the tpl_toolsevent function takes as its first parameter $toolsname from which it creates a TEMPLATE_TOOLSNAME_DISPLAY event.  An admin could then call tpl_toolsevent(toolsname,array()) at a convenient place in the template.  The plugin handling that event would then take care of creating the link.
Myron Turner
github: https://github.com/turnermm
plugins, templates: http://www.mturner.org/devel
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Go to forum
Imprint
This board is powered by the Unclassified NewsBoard software, 20150713-dev, © 2003-2015 by Yves Goergen
Current time: 2019-12-14, 00:45:49 (UTC +01:00)