Skip to Content Skip to Menu

🕒 Save Time and Effort with CB Editor Assistant: Effortlessly create and refine content in Joomla 3, 4, & 5.
🎁 Limited Offer: Enjoy a 5-day FREE trial and save up to 30% afterward!

[SOLVED] Help with conditionals syntax for #displayed

  • Pomond
  • Pomond
  • OFFLINE
  • Posts: 64
  • Thanks: 17
  • Karma: 5
7 years 9 months ago - 7 years 9 months ago #292599 by Pomond
Hello! I'm having some problems getting my conditionals to appear as I wish, and I think I've exhausted what I can clean from the tutorials, the YouTube videos and other answers here in the forum.

Basically, when viewing a user's profile, I'd like their Username (formatted name) to display at the top of their profile UNLESS the end user is able to see the firstname/lastname fields, in which case these would display instead.

Here's the code I'm using:

[cb:if firstname="#displayed"][firstname][cb:else][username][/cb:else][/cb:if]

When viewing the profile, only the username displays, and not the firstname, even though I can view this field output in other tabs.

What am I missing here? Can you help me out? Thanks in advance!
Last edit: 7 years 9 months ago by krileon. Reason: Added [SOLVED] tag to subject

Please Log in or Create an account to join the conversation.

  • Pomond
  • Pomond
  • OFFLINE
  • Posts: 64
  • Thanks: 17
  • Karma: 5
7 years 9 months ago #292600 by Pomond
Just to be clear, it's the Privacy plugin settings which I would like to affect firstname versus username display: If the user's profile privacy settings allow the current viewer to view firstname, I want them to be able to view it; if the privacy settings do not allow it, I want it to fall back to show the username instead.

Please Log in or Create an account to join the conversation.

  • Pomond
  • Pomond
  • OFFLINE
  • Posts: 64
  • Thanks: 17
  • Karma: 5
7 years 9 months ago #292603 by Pomond
I overlooked mentioning that I'm using a Custom HTML field type to render the result I want.

I can get this to work fine:
[cb:if firstname!=""][firstname][cb:else][username][/cb:else][/cb:if]

However, I don't want firstname to display, and for username to display instead, if the user's privacy settings wouldn't normally allow firstname to be viewed.

Hopefully that explains it a bit more.

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48709
  • Thanks: 8319
  • Karma: 1447
7 years 9 months ago - 7 years 9 months ago #292623 by krileon
Replied by krileon on topic Help with conditionals syntax for #displayed

[cb:if firstname="#displayed"][firstname][cb:else][username][/cb:else][/cb:if]

That's not a valid usage of #displayed, which only applies to the "user" parameter. Please read the substitution tutorial below carefully.

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

IF conditions are also against raw database values. They will not be conditioned (CB Conditional) or privacy checked (CB Privacy). There's not really a usage to cover what you're wanting. CB Privacy has a feature ticket to implement a parameter that overrides the field output instead of just emptying it. So instead of the field being removed from display entirely it'll instead display whatever you supply. This is noted in the below ticket.

forge.joomlapolis.com/issues/5183

Only way I can think of to force it is to use a Custom HTML field to substitute in the HTML value of the firstname field then condition against the Custom HTML field. That might work as the HTML output will be checked for privacy.


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.
Last edit: 7 years 9 months ago by krileon.
The following user(s) said Thank You: Pomond

Please Log in or Create an account to join the conversation.

  • Pomond
  • Pomond
  • OFFLINE
  • Posts: 64
  • Thanks: 17
  • Karma: 5
7 years 9 months ago - 7 years 9 months ago #292635 by Pomond
Thanks for your reply. I figured I was using #displayed incorrectly. I'm going to work around this for now by adjusting CSS to make the layout a bit more palatable.

You wrote:

Only way I can think of to force it is to use a Custom HTML field to substitute in the HTML value of the firstname field then condition against the Custom HTML field. That might work as the HTML output will be checked for privacy.


Well, I've been playing around with this, and I believe I have it working ... to a degree.

I created a first Custom HTML field called cb_firstnameconditional. I then placed the following code within it:
Code:
[cb:userfield field="firstname" /]
This field is set to not display on profile, edit, or registration.

I then created a second Custom HTML field called cb_firstnamedisplay. I then placed the following code within it:
Code:
[cb:if cb_firstnameconditional!=""][cb:userfield field="firstname" /][/cb:if]
This cb_firstnamedisplay field was then set to display in the profile, in the tab placed in the Canvas Title position.

When testing, this seems to work: The cb_firstnamedisplay field hides/displays according to the end user's Privacy settings for the firstname field.

Now I'm having problems with adding an Else to this. I change the cb_firstnamedisplay to the following:
Code:
[cb:if cb_firstnameconditional!=""][cb:userfield field="firstname" /][cb:else][username][/cb:else][/cb:if]

The elements inside the Else statement do not render: I've tried replacing [username] with [cb:userfield field="username" /] and even just a test text string, but no joy. Any idea why the Else element doesn't render? Note that this is the case no matter the privacy settings for [firstname].

I will note that the following code in cb_firstnamedisplay will get the username to render (no Else statement) while still respecting privacy for [firstname]:
Code:
[cb:if cb_firstnameconditional!=""][cb:userfield field="firstname" /][/cb:if][username]

Any ideas what's up here?
Last edit: 7 years 9 months ago by Pomond.

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48709
  • Thanks: 8319
  • Karma: 1447
7 years 9 months ago #292643 by krileon
Replied by krileon on topic Help with conditionals syntax for #displayed
My guess is your IF usage isn't actually working and the condition is always passing resulting in ELSE never taking affect. Try the below as CB Privacy and CB Conditional set the value to " " (a space) as the API in CB it self is specifically checking for that (it's a legacy usage we'll clear up in a later CB release).

Code:
[cb:if cb_firstnameconditional!=" "][cb:userfield field="firstname" /][cb:else][username][/cb:else][/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: Pomond

Please Log in or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum