I'm trying to find a variable that will show when the content is new/has been updated to a logged in user.

I'm creating a different template for the teaser view of my "stories" content type. I'm trying to pull in a much more detailed "teaser" view and one of the things I want is the ability to show users when there is new content, or updated content (just like you can in most themes/etc). This is also pretty easily done in the Views module but I prefer Contemplate over Views for this since I have much more control with the data.

I've got it showing when new comments are posted, etc., but I really seem to be struggling to find the variable for the content if it's new to the user or not. I know this is user specific and they would need to be logged in, but there is already this ability for comments, and in all of the examples that contemplate pulls in I can never find the Teaser Variable for this specific value.

Any help?

Comments

jrglasgow’s picture

the information about what nodes a user has viewed is in the history table. to access it you would need to do a database query, something like this:

global $user;
$sql = "
  SELECT
    timestamp
  FROM
    {history}
  WHERE
    uid='%d' AND
    nid='%d'
";
$timestamp = db_result(db_query($sql, $user->uid, $node->nid));
// if we  don't have a result the user has never viewed the node
if (!$timestamp) {
  // the user has never viewed the node
  $new = TRUE;
} // the user has viewed the node, check to see if the node has changed
else if ($node->changed > $timestamp){
  // the node has changed since the last time the user looked at it
  $updated = TRUE;
}

this code should work, but it has never been tested.