Jump to content

Check if Custom Profile Field is Yes/No


LukasGr.

Recommended Posts

Posted

Hi guys,

I need your help.
I am looking for a way to check if a custom profile field (YES/NO field) is checked (=1) or not, globally! So not only on a forum post or anything, no - it needs to be displayed all around the website.

The code should check if the visitor is logged in AND if he has the custom profile field on Yes (required field during registration if yes or no). If requirements are met, then content should be shown otherwise no content. (this is used for a block for example but even in parts of the design template)

So far I came up with the following:

{{if \IPS\Member::loggedIn()}}
	{{$member = \IPS\Member::loggedIn();}}
	{{$fieldData = $member->ProfileFields()['core_pfieldgroups_4']['core_pfield_14'];}}
      {{if $fieldData === ?????}}
      	{CONTENT I WANT TO DISPLAY}
      {{endif}}
{{endif}}

I need help with the IF statement as non of my assumings worked. I checked whether the fieldData === 1, '1', "1" or even "Yes", "yes" etc. I know the custom profile field value is stored as string in my MYSQL database and therefore I assumed that a quoation mark would be essential. Nothing helped. When I try to display $fieldData it shows me Yes or No depending on what i set the value on my profle editing. 

Moreover, it seems to display a key string because it is translated to any other language as well. How can I get the true value (1 or 0) and check that with my if statement?

I tried helping myself with the search but nothing really helped me.

Posted

This post onwards gives you the answer as to why it doesn't equal 0/1 or no/yes, and provides a method to overcome it:

{{if \IPS\Member::loggedIn()}}
	{{$member = \IPS\Member::loggedIn();}}
	{{$fieldData = $member->ProfileFields()['core_pfieldgroups_4']['core_pfield_14'];}}
	{{if $fieldData === $member->language()->addToStack('yes')}}
		{CONTENT I WANT TO DISPLAY}
	{{endif}}
	{{if $fieldData === $member->language()->addToStack('no')}}
		{CONTENT I WANT TO DISPLAY}
	{{endif}}
{{endif}}

 

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...