CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Profiles (Moderator: Dave Greenberg) »
  • Include drupal block in profile listings
Pages: [1]

Author Topic: Include drupal block in profile listings  (Read 781 times)

andersiversen

  • I post occasionally
  • **
  • Posts: 76
  • Karma: 1
  • CiviCRM version: 4.4.4
  • CMS version: Drupal 7.26
  • MySQL version: 5.5.32
  • PHP version: 5.3.10
Include drupal block in profile listings
October 03, 2011, 12:57:07 pm
Just wanted to share some code on how to include a Drupal block in profile listings - it took me some hours of googling, and maybe this will save someone else the time used searching etc.

I have a profile that I use to list all contacts in a group (in my case the profile is used for searching for employers), but I wanted a set of instructions above the listing itself. Part of the reason for doing this, is that the web editors have easy access to editing Drupal content, and are familiar with that, and not so much with civicrm - not yet anyways :)

To make a custom listing follow the documentation here:
http://wiki.civicrm.org/confluence/display/CRMDOC40/Customize+Built-in,+Profile,+Contribution+and+Event+Registration+Screens

In this case my custom templates and php files are stored under sites/default/files/civicrm/custom/ so i copied Listings.tpl to sites/default/files/civicrm/custom/CRM/Profile/Page/12 making the directories CRM/Profile/Page/12 myself - 12 because the profile gid of the profile I'm customizing is 12.

I then edited the copy of Listings.tpl to include the following code:

Code: [Select]
{* make sure there are some fields in the selector *}
{if ! empty( $columnHeaders ) || $isReset }

{* my addition to the code *}

{php}
    include('block.php');
{/php}

{$block}

{* end of my addition to the code *}

{if $search}
<div class="crm-block crm-form-block">

You can read more about smarty's syntax, which is used in the templates, here: http://www.smarty.net

I then made the php-script block.php and put it in sites/default/files/civicrm/custom/:

Code: [Select]
<?php
         $block 
= block_load('block', '3');
         
$block_content = _block_render_blocks(array($block));
         
$build = _block_get_renderable_array($block_content);
         
$block_rendered = drupal_render($build);
         
$this->assign('block', $block_rendered); 
?>


The block in $this->assign('block', $block_rendered); is the variable that is referenced in the template above.
I guess you can embed all kind of drupal stuff in similar ways, but you'll have to figure that out yourself - read more about the block specific example here: http://drupal.org/node/26502

You might need to clear your templates in the templates_c directory as is written in the documention for customizing profiles (link near top of this post)

That's it ! Now, when you go to your profile listing (something like www.example.com/civicrm/profile?reset=1&force=1&gid=12) your drupal block is displayed at the top !

Cheers :)

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Profiles (Moderator: Dave Greenberg) »
  • Include drupal block in profile listings

This forum was archived on 2017-11-26.