How to add items to user drop-down

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
philmills
User
Posts: 555

How to add items to user drop-down

Post by philmills »

I'm trying to use prependTo or appendTo to add items into the user dropdown, but it doesn't work correctly.
in Page_Foot:

	<!-- prepend to user dropdown -->
	<script type="text/html" class="ew-js-template" data-name="UserDropdownMods" data-method="prependTo" data-target="#change-password" data-seq="11">
    <a class="dropdown-item" id="user-profile" data-action="redirect" data-url="./MySettingsList"><?php echo Language()->phrase('ClassActUserMenu_1'); ?></a>
    <a class="dropdown-item" id="user-assets" data-action="redirect" data-url="./MyAssetsList"><?php echo Language()->phrase('ClassActUserMenu_2'); ?></a>
    <a class="dropdown-item" id="user-docs" data-action="redirect" data-url="./StaffDocumentsView1List"><?php echo Language()->phrase('ClassActUserMenu_3'); ?></a>
	</script>
	<!-- end prepend to user dropdown -->

The HTML output from that is as follows, which as you can see appends the new items between the <a> and </a> tags of drop down item id 'change-password'. This looks to me to be incorrect behaviour.

<a class="dropdown-item" id="change-password" data-ew-action="redirect" data-url="/changepassword"><a class="dropdown-item" id="user-profile" data-action="redirect" data-url="./MySettingsList">My settings</a>
    <a class="dropdown-item" id="user-assets" data-action="redirect" data-url="./MyAssetsList">My assets</a>
    <a class="dropdown-item" id="user-docs" data-action="redirect" data-url="./StaffDocumentsView1List">My docs</a>Change Password</a>

What's wrong?
Do I have to replaceAll the entire dropdown?


philmills
User
Posts: 555

Post by philmills »

I kinda figured it out, it's not perfect because i wanted it to appear along with the other menu items below the username, but there is no id or unique class to prepend it to in that position.
Instead i added a divider and placed it above the username as a separate dropdown section.
Also I had a few typos, so here's the updated code that's working, in case anyone else finds it useful:

	<!-- prepend to user dropdown as separate section with divider -->
	<script type="text/html" class="ew-js-template" data-name="UserDropdownMods" data-method="prependTo" data-target=".dropdown-menu-end" data-seq="11">
    <a class="dropdown-item" id="user-profile" data-ew-action="redirect" data-url="/MySettingsList"><?php echo Language()->phrase('ClassActUserMenu_1'); ?></a>
    <a class="dropdown-item" id="user-assets" data-ew-action="redirect" data-url="/MyAssetsList"><?php echo Language()->phrase('ClassActUserMenu_2'); ?></a>
    <a class="dropdown-item" id="user-docs" data-ew-action="redirect" data-url="/MyDocumentsList"><?php echo Language()->phrase('ClassActUserMenu_3'); ?></a>
	<div class="dropdown-divider"></div>
	</script>
	<!-- end prepend to user dropdown -->

philmills
User
Posts: 555

Post by philmills »

fixed it with:
data-method="insertAfter" data-target=".dropdown-header"


Post Reply