Hi,

I am working on getting my calendar views setup to allow 'print-friendly' output. To do this I am embedding a view in a node, like this:

<?php
print views_embed_view('calendar', 'calendar_1');
?>

This works fine, but I'd like to be able to specify the month for the view which means I need to pass args to the view.

My url would look like this (using pathauto):

http://www.my.site/content/print-calendar/2010-01

But, I can't figure out what I need to add to the php embedding to get my argument to work with the view. I've tried variations of this:

<?php
print views_embed_view('calendar', 'calendar_1', $args[2]);
?>

with no luck (the system throws a 404 error).

Any help would be greatly appreciated.

Comments

kongoji’s picture

I had your same problem. The workaround I found was to don't pass arguments in views_embed_view, but to let a custom php script in views' date argument do the job picking the date from url.

Example:

print views_embed_view('calendar', 'calendar_1');
 

Then in the view's date argument (using your url http://www.my.site/content/print-calendar/2010-01):

  • in "Action to take if argument is not present" choose "Provide default argument"
  • in "Default argument type" choose "PHP Code"
  • in "PHP argument code" insert
     return arg(2);
    

Change the code to better fit your needs. Hope it helps!

Artusamak’s picture

Issue summary: View changes
Status: Active » Closed (outdated)

6.x is entirely unmaintained.