Hi,

I've been using content profile for a while and now I'm getting into block development.
I've developed a few blocks that pull content from the user's content profile and dispaly it in diferent parts of the site.
I don't have any cacheing enabled but I was wondering what would be the best cache option.
I was thinking about per user cache, but what will happen if the user modifies something from its content profile?
Is there an explicit way to expire the cached blocks when the content profile is updated?

Thanks!

Comments

josepvalls’s picture

I probably should say that those blocks do some intense calculations and pull information from views so it would be not very good to have to calculate them for every page view.

Bilmar’s picture

Could you please share the code used in the custom blocks? Thank you

josepvalls’s picture

Sure! I'll copy the simplest of the blocks. Not the best code, but you will get the idea. What will happen when the user fills in or changes his profile if this block is cached.

function menu_shortcuts_block($op='list', $delta=0, $edit=array()) {
switch ($op) {
case 'list':
	$blocks[0]['info'] = t('Welcome user short message');
	// This might be a bad idea!
	$blocks[0]['cache'] = BLOCK_CACHE_PER_USER;
	return $blocks;
case 'view':
	$blocks['subject'] = t('Welcome');
	global $user;
	if (in_array('cliente', $user->roles)){
		$profile = content_profile_load('cliente', $user->uid, $lang = '');
		$name = $profile->title;
	}elseif (in_array('candidato', $user->roles)){
		$profile = content_profile_load('candidato', $user->uid, $lang = '');
		$name = $profile->field_candidato_nombre[0]['value'];
	}else
		$name = t('User');
	if ($name)
		$blocks['content'] = "<div>Hello $name!</div>";
	else
		$blocks['content'] = "<div>Did you just register? <a href=\"/user/profile\">Remember to fill in your profile</a>!</div>";
	return $blocks;
	}
}
adpo’s picture

Is it possible to show Content profile block on specific pages?

- node type: ie. advertisement

and

- block will show content profile for the node author.

using PHP?

Thank you for reply.

josepvalls’s picture

I don't think your question relates at all to mine but yes, you can write a module in PHP that provides a block that checks the current node's content type and then would load and render the profile of the node's author.

adpo’s picture

Hi, thank you for reply, could you show me an example how to load and render the profile of the node's author.

josepvalls’s picture

Title: Content in blocks » Expire content profile content in cached blocks

You may get the node's author by $node=node_load(arg(1)); use content_profile_load with $node->uid (or node_load) to load the node and then render it into the block's body using node_view.

I changed the subject of the issue to reflect the problem I was trying to address in the beginning, please create your own issue for your questions

benone’s picture

What about enabling profile module and use Account information block (block comes with profile module) for displaying content profile fields ?

I copied profile-block.tpl.php to my theme folder and edit this adding:

$node_profile = content_profile_load(profile, $account->uid);
      if ($node_profile) {
         print_r($node_profile);
      }

You have all the content profile fields in a block which always appears next to the user nodes and its cached already by drupal core.

Am I right ?