Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
How to add attributes to the MeModule Smarty code?
pavsid
New
Hi, I would like to add an attribute canvas=""
to the rendered MeModule.
The Smarty module which renders it is in default.master.tpl
as {module name="MeModule" CssClass="Inline FlyoutRight"}
.
How can I make it render like this - <div class="MeBox Inline FlyoutRight" canvas="">...</div>
Many thanks.
0
Best Answer
-
vrijvlinder MVP
Make a folder called modules inside the views folder of your theme and clone the me.php into that folder. You can then modify it as you wish.
You can add attributes vis jQuery inside your theme template, also in the views folder of your theme.
Bellow is the me.php showing the added canvas attribute. And bellow that an example of how to use jQuery to add an attribute.
<?php if (!defined('APPLICATION')) exit(); $Session = Gdn::Session(); $User = $Session->User; $CssClass = ''; if ($this->CssClass) $CssClass .= ' '.$this->CssClass; $DashboardCount = 0; // Spam & Moderation Queue if ($Session->CheckPermission('Garden.Settings.Manage') || $Session->CheckPermission('Garden.Moderation.Manage')) { $LogModel = new LogModel(); //$SpamCount = $LogModel->GetOperationCount('spam'); $ModerationCount = $LogModel->GetOperationCount('moderate'); $DashboardCount += $ModerationCount; } // Applicant Count if ($Session->CheckPermission('Garden.Users.Approve')) { $RoleModel = new RoleModel(); $ApplicantCount = $RoleModel->GetApplicantCount(); $DashboardCount += $ApplicantCount; } if ($Session->IsValid()): echo '<div class="MeBox'.$CssClass.'">'; echo '<div class="WhoIs">'; echo '<h4>'.UserAnchor($User, 'Username').'</h4>'; echo '<div class="MeMenu">'; // Notifications $CountNotifications = $User->CountNotifications; $CNotifications = is_numeric($CountNotifications) && $CountNotifications > 0 ? '<span class="Alert">'.$CountNotifications.'</span>' : ''; echo UserPhoto($User); echo '<span class="ToggleFlyout" rel="/profile/notificationspopin">'; echo Anchor(Sprite('SpNotifications', 'Sprite Sprite16').Wrap(T('Notifications'), 'em').$CNotifications, UserUrl($User), 'MeButton FlyoutButton', array('title' => T('Notifications'))); echo Sprite('SpFlyoutHandle', 'Arrow'); echo '<div class="Flyout FlyoutMenu" canvas=""></div></span>'; // Inbox if (Gdn::ApplicationManager()->CheckApplication('Conversations')) { $CountInbox = GetValue('CountUnreadConversations', Gdn::Session()->User); $CInbox = is_numeric($CountInbox) && $CountInbox > 0 ? ' <span class="Alert">'.$CountInbox.'</span>' : ''; echo '<span class="ToggleFlyout" rel="/messages/popin">'; echo Anchor(Sprite('SpInbox', 'Sprite Sprite16').Wrap(T('Inbox'), 'em').$CInbox, '/messages/all', 'MeButton FlyoutButton', array('title' => T('Inbox'))); echo Sprite('SpFlyoutHandle', 'Arrow'); echo '<div class="Flyout FlyoutMenu" canvas=""></div></span>'; } // Bookmarks if (Gdn::ApplicationManager()->CheckApplication('Vanilla')) { echo '<span class="ToggleFlyout" rel="/discussions/bookmarkedpopin">'; echo Anchor(Sprite('SpBookmarks', 'Sprite Sprite16').Wrap(T('Bookmarks'), 'em'), '/discussions/bookmarked', 'MeButton FlyoutButton', array('title' => T('Bookmarks'))); echo Sprite('SpFlyoutHandle', 'Arrow'); echo '<div class="Flyout FlyoutMenu" canvas=""></div></span>'; } // Profile Settings & Logout echo '<span class="ToggleFlyout">'; $CDashboard = $DashboardCount > 0 ? Wrap($DashboardCount, 'span class="Alert"') : ''; echo Anchor(Sprite('SpOptions', 'Sprite Sprite16').Wrap(T('Account Options'), 'em').$CDashboard, '/profile/edit', 'MeButton FlyoutButton', array('title' => T('Account Options'))); echo Sprite('SpFlyoutHandle', 'Arrow'); echo '<div class="Flyout MenuItems" canvas="">'; echo '<ul>'; // echo Wrap(Wrap(T('My Account'), 'strong'), 'li'); // echo Wrap('<hr />', 'li'); if (C('Garden.UserAccount.AllowEdit') && C('Garden.Registration.Method') != 'Connect') { echo Wrap(Anchor(Sprite('SpEditProfile').' '.T('Edit Profile'), 'profile/edit'), 'li'); } else { echo Wrap(Anchor(Sprite('SpEditProfile').' '.T('Preferences'), 'profile/preferences'), 'li'); } if ($Session->CheckPermission('Garden.Settings.Manage') || $Session->CheckPermission('Garden.Moderation.Manage')) { echo Wrap('<hr />', 'li'); $CApplicant = $ApplicantCount > 0 ? ' '.Wrap($ApplicantCount, 'span class="Alert"') : ''; $CSpam = ''; //$SpamCount > 0 ? ' '.Wrap($SpamCount, 'span class="Alert"') : ''; $CModeration = $ModerationCount > 0 ? ' '.Wrap($ModerationCount, 'span class="Alert"') : ''; echo Wrap(Anchor(Sprite('SpApplicants').' '.T('Applicants').$CApplicant, '/dashboard/user/applicants'), 'li'); echo Wrap(Anchor(Sprite('SpSpam').' '.T('Spam Queue').$CSpam, '/dashboard/log/spam'), 'li'); echo Wrap(Anchor(Sprite('SpMod').' '.T('Moderation Queue').$CModeration, '/dashboard/log/moderation'), 'li'); if ($Session->CheckPermission('Garden.Settings.Manage')) { echo Wrap(Anchor(Sprite('SpDashboard').' '.T('Dashboard'), '/dashboard/settings'), 'li'); } } $this->FireEvent('FlyoutMenu'); echo Wrap('<hr />'.Anchor(Sprite('SpSignOut').' '.T('Sign Out'), SignOutUrl()), 'li', array('class' => 'SignInOutWrap SignOutWrap')); echo '</div>'; echo '</span>'; // Sign Out // echo Anchor(Sprite('SpSignOut', 'Sprite16').Wrap(T('Sign Out'), 'em'), SignOutUrl(), 'MeButton', array('title' => T('Sign Out'))); echo '</div>'; echo '</div>'; echo '</div>'; else: echo '<div class="MeBox MeBox-SignIn'.$CssClass.'">'; echo '<div class="SignInLinks">'; echo Anchor(T('Sign In'), SignInUrl($this->_Sender->SelfUrl), (SignInPopup() ? ' SignInPopup' : ''), array('rel' => 'nofollow')); $Url = RegisterUrl($this->_Sender->SelfUrl); if(!empty($Url)) echo ' <span class="Bullet">•</span> '.Anchor(T('Register'), $Url, 'ApplyButton', array('rel' => 'nofollow')).' '; echo '</div>'; echo ' <div class="SignInIcons">'; $this->FireEvent('SignInIcons'); echo '</div>'; echo '</div>'; endif; jQuery in a tpl master template: {literal} <script type="text/javascript"> jQuery(document).ready(function($){ $('.Flyout.MenuItems').attr("canvas"); }); </script> {/literal}
6
Answers
I would say that there is no good way to do so
You can use JavaScript to add such an attribute, but I bet you haven't searched for that answer.
You could copy /applications/dashboard/views/modules/me.php to your theme and make the change in that file.
You could copy the default.master.tpl to your theme and enclose the MeBox with a
<div canvas="">
(if that would help at all)But that's pretty much all you can do. No clever solution here...
Make a folder called modules inside the views folder of your theme and clone the me.php into that folder. You can then modify it as you wish.
You can add attributes vis jQuery inside your theme template, also in the views folder of your theme.
Bellow is the me.php showing the added canvas attribute. And bellow that an example of how to use jQuery to add an attribute.
❌ ✊ ♥. ¸. ••. ¸♥¸. ••. ¸♥ ✊ ❌
Doh, thanks folks, completely forgot i'm already using a custom
/modules/me.php
!!Have added it to this line....
echo '<div class="MeBox'.$CssClass.'" canvas="">';
Many thanks for your help - sorted!