Skip Navigation

[Resolved] I want to switch the display for each role using a conditional branching block.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 3 replies, has 1 voice.

Last updated by Minesh 21 hours, 7 minutes ago.

Assisted by: Minesh.

Author
Posts
#2860069
single post for member.png
conditional.png

Dear support team,

I am currently building a members-only website at hidden link.
The member roles are as follows:
• Guest (Not logged in)
• Basic (Free member)
• Premium (Paid member)
I want to create and display content for each of the above roles. Following the Toolset documentation, I've devised the following method:
Combine "Content Templates" + "Conditional Branching" + "Access Control".
01
Create 3 types of templates
Create three content templates for Guest, Basic, and Premium using Toolset → Content Templates.
02
Create a Premium template
Create a full-content template for Premium members, displaying the regular body text as is.
03
Create a Basic template
Create a template including a teaser and upgrade button, displaying it only to Basic members.
04
Create a Guest template
Create a template including login prompts and registration buttons, displaying it to users who are not logged in.

05
Add a conditional branching block
Use Toolset's conditional branching within each template to switch the displayed content according to the user's role.
06
Assign a template to a post type
Apply the created template to the target post type (in my case: Blog=posts).
07
Integrate with access control
Set Basic and Premium viewing permissions in Toolset Access to fully synchronize with template switching.
My current challenge is:
I want to switch the display based on the role using a conditional branching block.
Ultimately, I want to consolidate this into a single template as follows:
Example: Switching all roles in one template
Code
[wpv-conditional if="( $(wpcf-user-role) eq 'premium' )"]
...Full content for Premium...
[/wpv-conditional]

[wpv-conditional if="( $(wpcf-user-role) eq 'basic' )"]
...Teaser for Basic...
[/wpv-conditional]

[wpv-conditional if="( $(wpcf-user-logged-in) eq 'false' )"]
...Login prompt for Guest...
[/wpv-conditional]

I would like support on how to achieve these conditions in a single template (named "Single-post for members" in my site's case), as shown in the attached file. Please refer to the attached file.

Regards,

Yoshihiko

#2860100

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - you should add shortcode block or design the content template in the legacy mode that is much better as we need to check the user role and display the different content templates conditionally.

You can switch the main content template to legacy and try to add the following conditions:

[wpv-conditional if="('[wpv-current-user info='id']' eq '')" ]
/// display guest user template 
[wpv-post-body view_template="your-desired-content-template-slug-for-not-loggedin-user"]
[/wpv-conditional]


[wpv-conditional if="( '[wpv-current-user info="role"]' eq 'basic' )"]
 // if current user role is basic - display this content 
[wpv-post-body view_template="your-desired-content-template-slug-for-basic"]
[/wpv-conditional]

[wpv-conditional if="( '[wpv-current-user info="role"]' eq 'premium' )"]
// if current user role is premium- display this content 
[wpv-post-body view_template="your-desired-content-template-slug-for-premium"]
[/wpv-conditional]

More info:
- https://toolset.com/documentation/legacy-features/views-plugin/conditional-html-output-in-views/
- https://toolset.com/documentation/user-guides/views/views-shortcodes/#wpv-current-user

#2860605

Dear minesh,

By the way, should I understand that it's not possible to use the Toolset's "conditional" block to perform this switching? Or should I understand that switching is simply not possible?

If switching is possible, could you please explain how to use the Toolset's "conditional" block?

Regards,
Yoshihiko

#2860626

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

It's possible but this looks more redable code.

You can add the conditional block and configure the same condition and then add the content termplate block within the condition.