0

I need to allow users to turn off the public display of their profile if they wish too. I created a Boolean field to store whether the user wanted the profile shown or hidden. According to this (old!!) documentation on d.o., I should add an if statement at the beginning of the user profile template.

Specifically, is this the proper way to access the value?
Edit: Proper, but must account for possibility that value hasn't been set in existing profiles, thanks!

<?php //check to see that user has chosen to show profile
  if(!isset($field_profile_display) || $field_profile_display[0][value] == 1): ?> 

If I put the if statement at the very beginning of user-profile.tpl.php, I see all the fields set to display (with Display Suite), unthemed. If I put it after , I get a profile page, blank but fo the username as the title.

Where do I put the code to actually prevent the page from displaying? Does it need to go in page.tpl?

Generally, is this really still the best practice? Would it be better to implement this in a preprocess hook?

1

This way is absolutely okay. There is definitely the possibility to achieve the same result with the preprocess hook, but doing it in the template file is also a common "drupalish" way and has (as far as i know) no disadvantages.

One thing: Do you have already existing users? if so you should check if the variable exists before comparing it with a value... otherwise you could get a php-warning.

0

After implementing the code in a node template, I ran into errors running cron and site search. (This is a well known situation, see cron breaks on drupal_goto.) Ultimately, I think I will follow the advice given here in a question about an alternative Drupal goto function: Do not place 'custom' PHP code in nodes. I'm going to rewrite it as a preprocess hook.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.