Both solutions worked well! I went for your last suggestion above because of the user avatar beeing displayed in right proportions without beeing stretched/skewed.
Thank you for your time, pregrine! I wish to bother you with one last question.
What is the exact code for displaying the users' username as a clickable link?
My code for displaying the username for now, is: <?php echo $Session->User->Name ?> in default.master.php.
This is a great Thread, I was looking for ways to make the user name in the menu display the user image instead of the text/name...Using this method gave me the avatar but not replacing the text link , just added it above the menu. I also pilfered the who's online plugin for snippets but my results have not been satisfactory
tried different combos with odd results...what would be the best way to add the user image to that link?
I thought I could do it like this but I know it is not right:
$this->Menu->AddLink('User', Img('unknown link to user photo', array('title' => T('{Username}'), '/profile/{UserID}/{Username}',array('img class' =>'ProfilePhotoSmall'),array('Garden.SignIn.Allow'), array('class' => 'UserNotifications'));
A pretty neat Smarty variable was assigned for this sort of stuff: {$User}. It's only accesible through the Smarty templates though, but the function can easily be rewritten so you can use it elsewhere:
Lol, no worries :-) What you need to do is simply copy/paste the function I posted into your theme hooks inside the []ThemeHooks class:
<?php if (!defined('APPLICATION')) exit();
class YourThemeHooks implements Gdn_IPlugin {
[User() function goes here]
/**
* No setup required
*/
public function Setup() {
return TRUE;
}
/**
* No cleanup required
*/
public function OnDisable() {
return TRUE;
}
}
Then simply write the following to get the profile picture for the currently logged in user:
$this->User()['Photo'];
...or if you want to do it directly in the master view (this should work in theory):
I am able to add the image but what I get is the link not the image lmao Sometimes I get this stuff and sometimes I am lost....this is a php based theme not tpl or smarty. No themehooks except for the master.default.php .. That is where I am trying to put this stuff arg!
no it did not like the [ ] gives me syntax errors and unexpected this and that , I have been trying to figure this out for a while and thought maybe by now I could get a handle on it but seems I am still too green to be successful... I will keep trying some day it will dawn on me I hope thanks for the time and effort I really should understand this by now and it is embarrassing . how is it that I can replace anything with images and this I can't ?
Funny thing is it does give me the image but in text form as in the url of the image.
This is the section I am trying to add this to, I reverted the Photo changes I made this is how it looks original.
I replaced $Name with $Photo and tried a variety of things as well as your advice. Where in that section would you insert the changes, Maybe I need to make a theme hooks file for this theme....but I want to simplify not more complex, the point of the user image on the menu is to save menu space...specially if user has a long name..smells like what I need is a plugin called UNPhoto
You'll need to put the code I posted in a theme hooks file yes - as for simplicity, more is often less. A core concept of OOP is keeping your data in different and easily accesible objects - keeping your objects in separate files is a good idea after which you can access them using methods in e.g. your views. Here the ThemeHooks is your object and it lets you access user data using the User() method.
I went to dinner , needed a break , ok so the solution is to make a theme hooks.php for my theme to put the code above in there, ok I shall give it a whack and report...
wow the opposite of make up application...bass lines, food intake, I was trained to think less is more !! I must retrain my brain to think more is less. I learned that about the plugin relationship, more modules, less work along the line. The more work you put into a relationship the less you like the other person...I guess I could learn to think in those terms!
Sad to report I was too dense to get it to work...I added the class.vrijthemehooks.php as instructed with Kasper's code, tried to add the user part to the default but it rejected the [ ] and from then on just a minefield of syntax errors ... If I could understand the flowchart , but frustration has got the best of me on this matter..... I just can't seem to do it
Answers
In the continuing saga you can see which works best for you the one above or this one, if any.
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
Both solutions worked well! I went for your last suggestion above because of the user avatar beeing displayed in right proportions without beeing stretched/skewed.
Thank you for your time, pregrine! I wish to bother you with one last question.
What is the exact code for displaying the users' username as a clickable link?
My code for displaying the username for now, is:
<?php echo $Session->User->Name ?>
in default.master.php.I managed to do this myself by using:
<?php echo UserAnchor($User); ?>
Thank you all for your answers!
Great. You're learning, just experiment and things gradually become clearer and clearer.
whew!
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
Just used your final solution on my forum - works like a charm, thanks so much for sharing
This is a great Thread, I was looking for ways to make the user name in the menu display the user image instead of the text/name...Using this method gave me the avatar but not replacing the text link , just added it above the menu. I also pilfered the who's online plugin for snippets but my results have not been satisfactory
I want to add the user image to this link
tried different combos with odd results...what would be the best way to add the user image to that link?
I thought I could do it like this but I know it is not right:
❌ ✊ ♥. ¸. ••. ¸♥¸. ••. ¸♥ ✊ ❌
A pretty neat Smarty variable was assigned for this sort of stuff:
{$User}
. It's only accesible through the Smarty templates though, but the function can easily be rewritten so you can use it elsewhere:Put this in your theme hooks and you can to the following (tried and tested):
Kasper Kronborg Isager (kasperisager) | Freelance Developer @Vanilla | Hit me up: Google Mail or Vanilla Mail | Find me on GitHub
lol that wiped out everything , I am not getting this treat me like a noob lmao
❌ ✊ ♥. ¸. ••. ¸♥¸. ••. ¸♥ ✊ ❌
Lol, no worries :-) What you need to do is simply copy/paste the function I posted into your theme hooks inside the
[]ThemeHooks
class:Then simply write the following to get the profile picture for the currently logged in user:
...or if you want to do it directly in the master view (this should work in theory):
Kasper Kronborg Isager (kasperisager) | Freelance Developer @Vanilla | Hit me up: Google Mail or Vanilla Mail | Find me on GitHub
I am able to add the image but what I get is the link not the image lmao Sometimes I get this stuff and sometimes I am lost....this is a php based theme not tpl or smarty. No themehooks except for the master.default.php .. That is where I am trying to put this stuff arg!
❌ ✊ ♥. ¸. ••. ¸♥¸. ••. ¸♥ ✊ ❌
If you want to turn the image src into an
<img>
tag, do this:...or this:
Kasper Kronborg Isager (kasperisager) | Freelance Developer @Vanilla | Hit me up: Google Mail or Vanilla Mail | Find me on GitHub
no it did not like the [ ] gives me syntax errors and unexpected this and that , I have been trying to figure this out for a while and thought maybe by now I could get a handle on it but seems I am still too green to be successful... I will keep trying some day it will dawn on me I hope thanks for the time and effort I really should understand this by now and it is embarrassing . how is it that I can replace anything with images and this I can't ?
Funny thing is it does give me the image but in text form as in the url of the image.
This is the section I am trying to add this to, I reverted the Photo changes I made this is how it looks original.
$Authenticator = Gdn::Authenticator(); if ($Session->IsValid()) { $Name = $Session->User->Name; $CountNotifications = $Session->User->CountNotifications; if (is_numeric($CountNotifications) && $CountNotifications > 0) $Name .= ' '.$CountNotifications.''; $this->Menu->AddLink('User', $Name, '/profile/{UserID}/{Username}',array('Garden.SignIn.Allow'), array('class' => 'UserNotifications'));
I replaced $Name with $Photo and tried a variety of things as well as your advice. Where in that section would you insert the changes, Maybe I need to make a theme hooks file for this theme....but I want to simplify not more complex, the point of the user image on the menu is to save menu space...specially if user has a long name..smells like what I need is a plugin called UNPhoto
❌ ✊ ♥. ¸. ••. ¸♥¸. ••. ¸♥ ✊ ❌
You'll need to put the code I posted in a theme hooks file yes - as for simplicity, more is often less. A core concept of OOP is keeping your data in different and easily accesible objects - keeping your objects in separate files is a good idea after which you can access them using methods in e.g. your views. Here the
ThemeHooks
is your object and it lets you access user data using theUser()
method.Kasper Kronborg Isager (kasperisager) | Freelance Developer @Vanilla | Hit me up: Google Mail or Vanilla Mail | Find me on GitHub
seconded.
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
I went to dinner , needed a break , ok so the solution is to make a theme hooks.php for my theme to put the code above in there, ok I shall give it a whack and report...
❌ ✊ ♥. ¸. ••. ¸♥¸. ••. ¸♥ ✊ ❌
wow the opposite of make up application...bass lines, food intake, I was trained to think less is more !! I must retrain my brain to think more is less. I learned that about the plugin relationship, more modules, less work along the line. The more work you put into a relationship the less you like the other person...I guess I could learn to think in those terms!
❌ ✊ ♥. ¸. ••. ¸♥¸. ••. ¸♥ ✊ ❌
I was trained to think less is more !!
think of it as "More || Less" (maybe translation "mas o menos")
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
Sad to report I was too dense to get it to work...I added the class.vrijthemehooks.php as instructed with Kasper's code, tried to add the user part to the default but it rejected the [ ] and from then on just a minefield of syntax errors ... If I could understand the flowchart , but frustration has got the best of me on this matter..... I just can't seem to do it
❌ ✊ ♥. ¸. ••. ¸♥¸. ••. ¸♥ ✊ ❌
post what you got and which files you put it in.
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
this is the vrijhooks I put it in the theme folder
then tried using
Img($this->User()['Photo'])
...or this:
Img(VrijThemeHooks::User()['Photo']) it did not like the [ ] tried removing them rewriting it no luck
in the section for the link in the default.php
❌ ✊ ♥. ¸. ••. ¸♥¸. ••. ¸♥ ✊ ❌