I want to let users submit pictures for thier profile, but choose whether to display them on stories.

I created a custom profile as a checkbox called profile_useImage. When selected, this is 1, when not selected, it's 0. The database is updated OK (I checked).

So I tried to change the node.tpl.php file for the theme. I changed the snippet

 if($picture) {
   print $picture;
}

to

 if ($picture && $user->profile_useImage) {
   print $picture;
}

Thinking that would toggle OK. The image does disappear, but that's probbaly because of an error. :) I can't make appear when I want.

Anyideas? Or is there a better way to do this?

thanks

Comments

nevets’s picture

Since it sounds like you want to allow the user to chose if their picture is show that seems like a reasonable solution (even simplier let them .choose to upload (or not) their image). The part that missing is that profile fields are not loaded as part of the user object by default so you need to call profile_load_profile(). Your snippet would them become

<?php
profile_load_profile($user);
 if ($picture && $user->profile_useImage) {
   print $picture;
}
?>
hal9000_jr’s picture

Thanks brother. That got it going.

iedude@remote.insidetheie.com’s picture

this is exactly what i'm trying to do, but it does not work for me..
i have created the profile_useImage field, and updated the .tpl.php file, but the image does not load. if i repalce it with just $picture it loads fine..
what am i missing here?
(4.7.4)

nevets’s picture

Did you update your profile/account? so the new field (useImage) has been selected/checked?

iedude@remote.insidetheie.com’s picture

hehe.. YESSS..

Not sure if it makes a difference or not, but i'm using FlatForum.. so i'm putting the code in node-forum.tpl.php .. like i said $Picture works fine, as well as a few other modifications i've added..

<?php
  if (!_is_forum()) {
    include('node.tpl.php');
    return;
  }
  $curr_user = user_load(array('uid' => $userid));
  $sig = $curr_user->signature;
  $loc = $curr_user -> profile_location;
?>



<div class="comment forum-comment comment-<?php print $row_class; print $comment->new ? ' comment-new forum-comment-new' : ''; ?>">

  <div class="comment-left">
    <div class="author-name"><?php print $name ?></div>
    <?php profile_load_profile($user);if ($picture && $user->profile_useImage) {print $picture;}?>

    <?php if (module_exist('flatforum')): ?>
      <span class="author-posts">
        <?php print t('Posts:') . ' ' . $posts; ?><br />
      </span>
      <span class="author-regdate">
        <?php print t('Joined:') . ' ' . $joined; ?><br />
	<?php echo t('Location:') . ' ' . $loc; ?>

	<?php print user_badges_for_uid($uid); ?>
	<?php print user_badges_for_uid($comment->uid); ?>
      </span>
    <?php endif ?>
  </div>

  <div class="comment-right">
    <div class="title"><?php print check_plain($comment->subject) ?></div>
    <?php if ($comment->new) : ?>
      <a id="new"></a>
      <span class="new"><?php print $new ?></span>
    <?php endif ?>
    <div class="content">
      <?php print $content ?>
      <?php if ($sig): ?>
        <div class="author-signature">--<br /><?//php print check_markup($sig); ?></div>
      <?php endif ?>
      <br class="clear" />
      <div class="links"><?php print $submitted ?><br />
	<?php print $links ?> 	</div>
    </div>
  </div>

</div>
<br class="clear" />
iedude@remote.insidetheie.com’s picture

changed $User to $curr_user and it's working..
I think i might be getting the hang of this PHP thing..