Reputation: 13537
I've setup a view in drupal that lists items like this:
IMAGE 1 | IMAGE 2 | IMAGE 3 | IMAGE 4
desc | desc | desc | desc
where "desc" is, you guessed it, a description of the node. What I need is to end up with something like this:
IMAGE 1 | IMAGE 2 | IMAGE 3 | IMAGE 4
desc | desc | desc | desc
EDIT | EDIT | EDIT | EDIT
ACTION | ACTION | ACTION | ACTION
Where EDIT goes to the edit page of the various nodes. Also, the ACTION signifies a button that I want to appear underneath the items that navigates to a page, let's call it http://www.mysite.com/action and takes the id as a parameter to end up with something like this: http://www.mysite.com/action/1.
I hope this all makes sense.
The pain in the ass way to solving this is to create a theme file views-view-NAME.tpl.php and manipulate the $rows variable. I just think there must be a better way and I'm obviously just missing something.
So, does anybody know how to do this?
Upvotes: 4
Views: 12937
Reputation: 101
For Drupal 8, I built the Views Any Route module, which lets you create buttons based on routes: https://www.drupal.org/project/views_any_route . The main use for the module is that access checking is included in the construction of the link, which would otherwise require a custom field, or Views Field View, etc.
In this case, if you use the Devel module, you can look up the "routes info" and find the correct route for a node path. You then create the Any Route button for that route, and pass the nid as a parameter (i.e. node={{ nid }}).
Upvotes: 0
Reputation: 3388
You can add links and then style them as buttons (if you really need it to look like a button) by doing something like this:
Add the following fields to your view:
In order to get that second field to be an arbitrary link containing the node ID, select the Output this field as a link option when configuring the field. In the Link path box, enter the desired link, something like this:
action/[nid]
or, you can use an absolute url
http://www.example.com/action/[nid]
Upvotes: 9