How can I add a link with a UID from a User Reference from a table in Drupal Views
I have the following in Drupal 6:
- A Master CCK type which contains a User reference field and other fields. There will only be one record per user here.
- A View of this CCK, shown as a table, with one of the fields being the user ref from the CCK type. This field is initially shown as a user name, linking to the user profile.
- A Second CCK type which can have several pieces of data about a particular user.
- A View for this CCK type, displaying information as a table. It takes a user id as an argument (an integer)
I want to click on the user name in the master view, and be directed to the detail view for this user. To do this, I tried selecting 'Output this field as a link' on the user field. The thing available for me to replace are:
Fields
* [field_my_user_ref_uid_1] == Content:开发者_StackOverflow中文版 User (field_my_user_ref)
Arguments
* %1 == User: Uid
However, the [field_my_user_ref_uid_1] element is replaced by the user name, and %1 seems to get replaced with an empty string. How can I put the user id in here?
Well, I'm not sure what the right way to do this is, but I'm solving it the hacky way I seem to be solving all my Views problems: by throwing jquery at it.
Currently, the User Ref field already has a link with the user id, so I've added this to the footer:
<script type="text/javascript">
$(function() {
var $rows = $("table.views-table tbody tr");
$rows.children("td:nth-child(1)").each(function() {
var $anchor = $(this).children("a");
var linkElements = $anchor.attr("href").split("/");
var userId = linkElements[linkElements.length - 1];
$anchor.attr("href","/my_detail_view/" + userId);
});
});
</script>
I hate that I have to do it like this, but I sure do love jquery.
精彩评论