Hello,

I was wondering if someone could help me with the code to check if content profile (named "profile") exists on the page.tpl.php

I am wanting to print a link for "Create Profile" if content profile does not exist, and print a link for "Edit Profile" if the content profile exists.

Many thanks!

Comments

YK85’s picture

would anyone be able to help with this?
im not able to find this in the documentation anywhere
thanks!

kpv’s picture

global $user;
$node->type = 'profile';
$node->language = 'en';
if(content_profile_profile_exists($node, $user->uid))
  {print ("<strong>exists</strong>");}
  else
     {print ("<strong>doesn't exist</strong>");}

Not sure about $node->language but it works.

For more details see: http://drupalcontrib.org/api/function/content_profile_profile_exists/6
http://drupal.org/node/49768
http://api.drupal.org/api/global/language

texas-bronius’s picture

Thanks for that snippet. A step further is to link right into the authenticated user's edit or create Content Profile form:

global $user;
$node->type = 'profile';
$node->language = 'en';
if(content_profile_profile_exists($node, $user->uid)) {
  print ("<strong>Profile exists</strong>");
} else {
  print (
    l('Create your Profile', 'user/'. $user->uid .'/edit/profile')
  );
}
YK85’s picture

Thanks for sharing!
I was wondering what the $node->language = 'en' is needed for?
Also, I found that 'user/'. $user->uid .'/edit/profile' doesn't work, but 'user/'. $user->uid .'/profile/profile' does work.
Is there a way to change the url of the profile edit page to '/profile/edit' without the 'user/'. $user->uid . on the site url?

<?php
global $user;
$node->type = 'profile';
if(content_profile_profile_exists($node, $user->uid)) {
  print l(t('Edit your Profile'), 'user/'. $user->uid .'/profile/profile');
} else {
  print l(t('Create your Profile'), 'user/'. $user->uid .'/profile/profile');
}
?>
krisis’s picture

The language part is only used in the query for translation purposes. When the translation module is found and the $node->type (in this case content type 'profile') allows for duplicating in different languages, the query will explicitly search for the user profile in that language.