Plugin

Archived
Forum
(read-only)

Switchee

ExpressionEngine 1.x, ExpressionEngine 2, ExpressionEngine 3, ExpressionEngine 4

Back to this add-on's main page
View Other Add-ons From Mark Croxton

     

Testing Custom Field

General

Todd Richards
Todd Richards

I’ve got a custom field named {resource_visibility}.  Basically, when the client enters something into their resource bank, they can use a Field Pack Switch to set it for Members (default - value=“members”) or Public (value=“public).

My goal would be to use a Switchee statement to run a certain set of code based on members or public.

If I cal the custom field in the template, I get the correct value.  However, my Switchee statement isn’t working.

{exp:switchee variable="{resource_visibility}" parse="inward"}
    {case value
="public"}
 
Public
    
{/case}

    {case value
="members" default="yes"}
 Members
    {
/case}
{
/exp:switchee} 

This is inside a {exp:channel:entries channel=“resources” ....} tag.

Any thoughts?  I just updated to 2.1.1 today.

Todd

Todd Richards
# 1
Todd Richards

In addition, I tried to use ifelse and it’s not working either…

{exp:ifelse parse="inward"}
 {if resource_visibility 
== "public"}
  
<p>This is public</p>
 
{if:else}
  
<p>This is members</p>
{/exp:ifelse} 
Todd Richards
# 2
Todd Richards

OK, last update - and I may have answered my own question….

I was using an {exp:ifelse parse=“inward”}{/exp:ifelse} statement earlier in the template too.  Am I only able to use one in a template?  When I took that one out, then my issue above worked as expected with a {exp:ifelse parse=“inward”} statement and a Switchee statement.  So I’m guessing that is a limitation?

I’ve used Switchee many times - love it.  But I don’t think I’ve run across this before (that I can think of)?

Todd

Mark Croxton
# 3
Developer
Mark Croxton

I’d guess your earlier {exp:ifelse} was throwing an error. That can happen if you’re trying to evaluate variables which are unparsed at the point it runs. Turn on debug=1 in your index.php file to view PHP errors. You can use {exp:ifelse} as many times as you need, in principle.

Todd Richards
# 4
Todd Richards

Thanks Mark.  I believe I’ve got it figured out.