[SOLVED] user:"#Me" within PHP Code field

3 months 6 days ago - 2 months 3 weeks ago #330500 by galanopd
I have the following
if ( $user->get( "user" ) == "#Me" ) { ... }else{}
added in a few
switch() { case
in a PHP Code field but I can't make it work.
How can I state it correctly other than "#Me"? I have even tried
[cb:userdata field user:"#Me"]
but no luck

EDIT: Also tried
[cbsubs:if user="#Me"]my code[/cbsubs:if]
(Content Plugins->Enable)

Please Log in to join the conversation.

3 months 6 days ago #330501 by krileon
Replied by krileon on topic user:"#Me" within PHP Code field
It can only be used in substitutions where noted in our substitution tutorial below.

www.joomlapolis.com/documentation/279-community-builder/tutorials/18353-using-substitutions-throughout-cb

it's also #me not #Me. It's important to follow the syntax we provided. None of the syntax's you're using are valid. Some examples of valid syntax as follows.

[cb:userdata field="user_id" user="#me" /]
[cb:userfield field="username" user="#me" /]
[cb:if user="#me" username="demo"]The viewing user has a Username of "demo".[/cb:if]


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.
The following user(s) said Thank You: galanopd

Please Log in to join the conversation.

3 months 6 days ago #330502 by galanopd
Replied by galanopd on topic user:"#Me" within PHP Code field
Now it works fine,

Thanks

Please Log in to join the conversation.

2 months 3 weeks ago - 2 months 3 weeks ago #330694 by galanopd
Replied by galanopd on topic user:"#Me" within PHP Code field
Within a Code field I have the following
if([cb:userdata field="user_id" user="#me" /]) {
echo "Show ONLY when I view MY profile";
Some code here....
print_r(something);
} else {
echo "Show something else when I view other's profile";
Some other code here...
print_r(something else);
}

If I use user="displayed" or user="displayedOrMe" it shows the "else" even on my profile.

So the question is, how can I make only this part of the code not to be visible to user="displayed" but only to user="#me" ?

Please Log in to join the conversation.

2 months 3 weeks ago #330700 by krileon
Replied by krileon on topic user:"#Me" within PHP Code field
Substitutions need to always be treated like strings so be sure they're surrounded in single quotes then cast them if necessary to whatever type you need. Code field has access to $user which is the user object of the user being displayed. You can use the below API to check if the displayed user is the viewing user.

API
$displayedUserId= $user->getInt( 'id', 0 );
$viewingUserId = \CBLib\Application\Application::MyUser()->getUserId();

Substitutions
$displayedUserId= $user->getInt( 'id', 0 );
$viewingUserId = (int) '[cb:userdata field="user_id" user="#me" /]';

With that you can compare the two however you like and use them in further API calls as needed.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.
The following user(s) said Thank You: galanopd

Please Log in to join the conversation.

2 months 3 weeks ago - 2 months 3 weeks ago #330718 by galanopd
Replied by galanopd on topic user:"#Me" within PHP Code field
Thank you,

Now it is working!
The following user(s) said Thank You: krileon

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.204 seconds

Facebook Twitter LinkedIn