开发者

How to use PHP in the header of a drupal view?

I have a drupal view, which displays a content type filtered by a url argmuent (e.g. category). Now i'd like to add a link in top of my view, which allows my users to add a new node. In the add form the argument field should be prepopulated with the value from the filter.

I think to archive this, i have to install the prepopulate module and add so开发者_运维百科me php-code to the header section of my view, which generates the link.

Any suggestions how to manage this?


If you are wanting to add php code to get the arguments passed to views in the views header section, do the following:

  1. Make sure that the PHP filter is turned on; this is a module that can be enabled
  2. In the header section use the following code:

$view = views_get_current_view();
// [0] is first arg, [1] is second etc.
$argumentOutput = $view-> args[0];

Remember to have the input format set to PHP code. This will get you the argument passed to views.


It would be a lot easier to override the template for the view and insert the code/markup there. Check out the Theming infomation inside the view to find out what to call your template.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜