0

On a Drupal 7 Site with Panels and Tokens I have a content-type for Events. For the "Page" (Panels) of a Event I like to add a hyperlink / button to add the event to the personal Google Calendar. This requires to build a hyperlink with some query-parameters in it. Eg:

<a href="http://www.google.com/calendar/event?action=
  TEMPLATE&text;=Brunch at Java Cafe&dates;=20060415T180000Z/
  20060415T190000Z&location;=Java Cafe, San Francisco, CA
  &details;=Try our Saturday brunch special:<br><br>French
  toast with fresh fruit<br><br>Yum!&trp;=true&sprop;=
  website:http://www.javacafebrunches.com&sprop;=name:Jave Cafe">

  <img src="//www.google.com/calendar/images/ext/gc_button2.gif">
</a>

My approach is to create a custom block with "Full Html" and add the above snippet. Then add tokens like [node:title] that should get replaced with the node's title etc. Afterwards I add this block to the Events page (Panels). The problem is that the tokens don't get replaced.

Any idea how I can build this links the most easiest way?

Thanks for help, Marc

Update: Got one step forward: I don't use a block but a "Custom Content" pane from Panels. Within this replacement is supported. The problem I now have is that the date/time doesn't get formatted right. I use "date" field-type (Date module). Any idea how I can format that date correctly?

2 Answers 2

2

You would want to override the template for the content type you're using, in your theme. If you're using a base theme, copy the node template into your theme and then change it there (don't change the base theme directly). More info on phptemplate and theming is on Drupal.org.

If you don't code, doing this in a View would work. Here's what I would do:

  1. Create a content type with plain text fields for all the things you need to make dynamic (if you haven't already done this)
  2. Create a View that only displays one item at a time.
  3. I'm not sure what your setup is exactly like, so it may take some creativity to filter it to display the right one. You might want to try something like References to relate an Event node to your particular node of your new content type, or configure some contextual filters to pick the right values based on the URL of the Event page, or something.
  4. Have your View create a Block and have that Block display on Event nodes
  5. Configure your View to rewrite output of a field and make all other fields excluded from display. Views seems to have the peculiarity of only allowing you to use tokens from fields that were added to the display before the field being rewritted so use the last one added.
  6. ????
  7. PROFIT

But that's a ton of work. You're better off going with the phptemplate option.

5
  • And where / how would you generate the dynamic content itself? Using Rules maybe? But then I could add a "Google Calendar" field to my Events and calculate it using Rules without the need to of a separate content-type. Seems I missed your point - I guess ;-)
    – Marc
    Aug 4, 2012 at 12:32
  • About templating: I didn't do a template yet but use the Panels module to configure that more or less complex event-pages.
    – Marc
    Aug 4, 2012 at 12:37
  • No, you wouldn't need Rules, you would just use the template to output something like <a href="<?php print($url);?>"><?php print($words_that_go_here);?></a>... etc. So you could use PHP directly in the template to manipulate any of the variables that the template can access.
    – beth
    Aug 4, 2012 at 12:45
  • And that Template is for the view only? Right? Is it possible to use PHP directly in a Panels pane to render/build such a link?
    – Marc
    Aug 4, 2012 at 17:01
  • The Template and View options are either/or. You could use code in your template to output your link OR you could do it without writing code by using views. I can't really speak to the issue of using PHP directly in Panels, but it strikes me as seeming vaguely less secure.
    – beth
    Aug 4, 2012 at 19:41
1

Your best bet is to add a new "Ctools content type" that generates your link with l(). I have a tutorial on that over in How does one create a new Ctools plugin.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.