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 Drupal Modules (Moderator: Donald Lobo) »
  • Displaying a block on specific CiviCRM Pages
Pages: [1] 2

Author Topic: Displaying a block on specific CiviCRM Pages  (Read 9298 times)

balleyne

  • I’m new here
  • *
  • Posts: 14
  • Karma: 1
  • CiviCRM version: 4.3.x
  • CMS version: Drupal 7.x
  • MySQL version: 5.x
  • PHP version: 5.3.x
Displaying a block on specific CiviCRM Pages
May 10, 2013, 04:48:08 pm
I'm trying to display a Drupal Menu Block for a conference section of my website. Each conference section consists of a couple CiviCRM pages -- the Event Info and Event Registration pages -- as well as a variety of Drupal pages -- some Views for the program and speaker bios, a Basic Page node for hotel and travel information, etc.

I've tried using two methods: the Context module (using either Path conditions or Menu conditions -- because all the Drupal and CiviCRM pages are part of the same Drupal menu), and a straight Block configured to display "only on the listed pages" with all of the paths listed. I can't get the menu block to display on the CiviCRM pages.

I suspected that it had to do with the CiviCRM query strings... and when I removed the query strings from the Menu Block configuration, it worked -- except now my one Conference Menu appears on every civicrm/event/info and civicrm/event/register page, which won't work once I add the second conference...

Is there any way to reference specific CiviCRM pages in Drupal Block/Context configuration that gets around this query string issue? Should I embed them in a node? Is there some URL alias trick (tried that a bit already)?

I guess my real question is: How can I configure Drupal to display a particular block on only two specific CiviCRM pages with query strings in their URLs (the event info and event registration pages for a specific event)?

Thanks,
Blaise

petednz

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4899
  • Karma: 193
    • Fuzion
  • CiviCRM version: 3.x - 4.x
  • CMS version: Drupal 6 and 7
Re: Displaying a block on specific CiviCRM Pages
May 10, 2013, 05:56:33 pm
Look fwd to an answer to this. We had exact same requirement - show a Menu Block across a bunch of pages based on path PLUS on the event register page.
only thing i could do was to add to civicrm/event/register
which was fine in this case as client only runs one event/conference per 6 months.
Sign up to StackExchange and get free expert advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

pete davis : www.fuzion.co.nz : connect + campaign + communicate

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: Displaying a block on specific CiviCRM Pages
May 13, 2013, 07:04:44 am
The issue here is that CiviCRM traces the event based on the session id (or some other "hidden" parameter) and so that's not exposed to most of the standard interfaces for Drupal. You could write PHP code to track the same thing and thus determine if the user is registering for event X or Y and then show the block based on that.
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

balleyne

  • I’m new here
  • *
  • Posts: 14
  • Karma: 1
  • CiviCRM version: 4.3.x
  • CMS version: Drupal 7.x
  • MySQL version: 5.x
  • PHP version: 5.3.x
Re: Displaying a block on specific CiviCRM Pages
May 13, 2013, 09:23:05 am
Quote
The issue here is that CiviCRM traces the event based on the session id (or some other "hidden" parameter) and so that's not exposed to most of the standard interfaces for Drupal.

Do you mean through the whole registration process? I'm actually just concerned with the first registration page -- I don't mind all that much if the menu were to disappear when the user is going through other pages in the registration process (don't want to encourage them to jump around at that point anyways).

The main registration page just traces the event in the query string, right? The path I'm looking at is: civicrm/event/register?id=1&reset=1

The problem is, the query string part doesn't work in Drupal. It'll work for civicrm/event/register -- but then it appears for all events. I'd like to use one Drupal menu for Event #1, and another for Event #2, etc... don't mind if it disappears on subsequent pages in the registration process.

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: Displaying a block on specific CiviCRM Pages
May 13, 2013, 09:47:39 am
The first page always has the ID in the URL, yes. For that you can use very simple PHP code and just match the URL string precisely. That's easy to do.
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

The Doctor

  • I post occasionally
  • **
  • Posts: 33
  • Karma: 1
  • CiviCRM version: 4.7.x
  • CMS version: Drupal 7.x
Re: Displaying a block on specific CiviCRM Pages
May 15, 2013, 07:43:41 am
I worked around this by configuring the block to display on:

civicrm/event/info

Mind you, this only works because we have only one event going on a year. If there were multiple events, the block would show up for all of them.

I am curious Hershel, how would one configure it using PHP to display on both the CiviCRM page and on the other listed pages it needs to appear on?

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: Displaying a block on specific CiviCRM Pages
May 16, 2013, 04:56:34 am
Quote from: The Doctor on May 15, 2013, 07:43:41 am
I am curious Hershel, how would one configure it using PHP to display on both the CiviCRM page and on the other listed pages it needs to appear on?

You must do it in PHP. See here http://drupal.org/node/134425 for the basic idea. That example is even more complicated, but anyway the last part there is what you would need--URL comparison.
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

Chris Burgess

  • Ask me questions
  • ****
  • Posts: 675
  • Karma: 59
Re: Displaying a block on specific CiviCRM Pages
September 19, 2013, 06:03:25 pm
Here's code for a similar requirement - showing a block only on a specific Contribute page (id=7).

As per comment, this could be more efficient if you did the first part (civicrm/contribute/transact) in Block Visibility settings, but then you're separating the visibility logic into two places - it might have a performance benefit but it makes it harder for developers to understand. I'm fighting for the humans.

https://gist.github.com/xurizaemon/6632034
@xurizaemon ● www.fuzion.co.nz

galgeek

  • I’m new here
  • *
  • Posts: 24
  • Karma: 1
  • CiviCRM version: 4.6.0
  • CMS version: drupal 7.36
  • MySQL version: 5.5
  • PHP version: 5.3
Re: Displaying a block on specific CiviCRM Pages
October 03, 2013, 12:01:39 pm
This code seems to be working nicely for me, to show a block on one specific contribution page, id=4, pasted into the block's Pages Visibility settings box with "Pages on which this PHP code returns TRUE (experts only)" enabled:

Code: [Select]
<?php
$match 
= FALSE;
if (
current_path() == 'civicrm/contribute/transact' && isset($_GET['id']) && $_GET['id'] == 4) { $match = TRUE; }
return 
$match;
?>

If at first you don't have the option of "Pages on which this PHP code returns TRUE (experts only)", you may find this helpful:  http://drupal.stackexchange.com/questions/82327/how-to-add-page-restrictions-for-blocks-in-drupal

petednz

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4899
  • Karma: 193
    • Fuzion
  • CiviCRM version: 3.x - 4.x
  • CMS version: Drupal 6 and 7
Re: Displaying a block on specific CiviCRM Pages
December 18, 2013, 09:40:13 pm
Kept meaning to post this option back here too
https://drupal.org/project/block_query

From memory, the block adds a new Visibility Setting called Query.

There you can set eg id=39

which means if you have Pages set to 'only on the listed pages' and eg

civicrm/event/register*

then it should only show on Event 39
« Last Edit: August 20, 2014, 01:53:28 pm by petednz »
Sign up to StackExchange and get free expert advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

pete davis : www.fuzion.co.nz : connect + campaign + communicate

gibsonoliver

  • I post occasionally
  • **
  • Posts: 65
  • Karma: 2
    • Northbridge Digital
Re: Displaying a block on specific CiviCRM Pages
February 11, 2014, 04:29:54 am
Hi

The code posted by Galgeek above works fine.
I've summarised below how, in Drupal 7, you can get blocks onto
- Contribution pages using the native URL
- Contribution pages using an aliased URL

Contribution pages using the native URL - i.e. URL is ../civicrm/contribute/transact?reset=1&id=1
In block settings/ Show block on specific pages / set to 'only on Pages on which this PHP code returns TRUE (experts only)'
The PHP Code is (change based on the contribution page ID)
<?php
$match = FALSE;
if (current_path() == 'civicrm/contribute/transact' && isset($_GET['id']) && $_GET['id'] == 17) { $match = TRUE; }
return $match;
?>

Contribution pages using an aliased URL - i.e. URL is ../someeventname
In block settings/ Show block on specific pages / set to 'only on Pages on which this PHP code returns TRUE (experts only)'
The PHP Code is (change based on the page URL)
<?php
$url = request_uri();
if (strpos($url, "someeventname")) {
return TRUE;
}

Olly
Oliver Gibson, Northbridge Digital

BrightBold

  • I’m new here
  • *
  • Posts: 16
  • Karma: 0
  • CiviCRM version: 4.4.4
  • CMS version: Drupal 7
  • MySQL version: Pantheon
  • PHP version: Pantheon
Re: Displaying a block on specific CiviCRM Pages
March 28, 2014, 08:59:22 am
If you're using Context to place blocks, there's also Context Query Parameters:
https://drupal.org/project/context_query_param

John.K

  • I post occasionally
  • **
  • Posts: 75
  • Karma: 5
  • CiviCRM version: 4.x
  • CMS version: Drupal 7
  • MySQL version: 5.x
  • PHP version: 5
Re: Displaying a block on specific CiviCRM Pages
June 23, 2014, 07:22:53 am
Unfortunately this really isn't that easy on events.

The first participant's registration page has the event ID (so there are various ways we can show the block on the page). But after that it switches to using a qfKey and loses all the 'obvious' indicators as so what the event ID is. It doesn't seem to even be posted in the form.

We're trying to implement some custom blocks (and a different theme if we can manage it) for all of the registration pages for one of our events. But at the moment that seems to be very difficult.

pmoz

  • I post occasionally
  • **
  • Posts: 101
  • Karma: 2
  • CiviCRM version: 4.4.0, 4.5.3
  • CMS version: Drupal 7.34
  • MySQL version: 5.1.68
  • PHP version: 5.4.9
Re: Displaying a block on specific CiviCRM Pages
March 21, 2015, 03:18:37 am
Thanks to Pete's suggestion, we successfully used the block_query module for individual event volunteers.

So in our case, we selected "Only the listed pages" and added vid=5 to the Queries tab in the block.

Easy as pie.
Quote
Kept meaning to post this option back here too
https://drupal.org/project/block_query

From memory, the block adds a new Visibility Setting called Query.

There you can set eg id=39

which means if you have Pages set to 'only on the listed pages' and eg

civicrm/event/register*

then it should only show on Event 39

The only negative to this solution is that you can't display the block on a static page and a query page.
« Last Edit: March 21, 2015, 05:17:33 am by pmoz »

petednz

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4899
  • Karma: 193
    • Fuzion
  • CiviCRM version: 3.x - 4.x
  • CMS version: Drupal 6 and 7
Re: Displaying a block on specific CiviCRM Pages
March 21, 2015, 05:41:37 pm
To have the same block show in different places you could try https://www.drupal.org/project/multiblock
Sign up to StackExchange and get free expert advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

pete davis : www.fuzion.co.nz : connect + campaign + communicate

Pages: [1] 2
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Drupal Modules (Moderator: Donald Lobo) »
  • Displaying a block on specific CiviCRM Pages

This forum was archived on 2017-11-26.