I have been working on creating a view which displays several fields from nodes as a table. In addition I would like to have the ability to delete the node corresponding to a row in the table. To do this I have added an extra field "Node: Delete link". The text of this field appears in the table as "Delete" and when I click on it, it takes me to the correct page (http://ncard/node/36/delete?destination=browse_contacts). So far so good :-)
However, what I want to do is substitute the default "Delete" text of the "Node: Delete link" field with an icon. I have tried to do this by editing "Rewrite the output of this field" option as: <img alt="Delete" src="sites/all/themes/ncard/images/delete.png" />
Then setting up the "Output this field as a link" option so that "link path" is set to "[delete_node]" ([delete_node] is a replacement pattern) and "target" is set to "_parent". After saving and opening the view I find that the icon is displayed, but the URL is wrongly written as "http://ncard/delete".
Any suggestions on what I am doing wrong? Is there another, perhaps easier, way I can replace the field text with an icon within a view?
Comments
.:.
Try the Views Custom Field module.
Are there other options?
Many thanks for the advice. I used the module and added this code to reconstruct the correct url and add icon:
If I do it this way I seem to loose a lot of the functionality of the "Node: Delete link" field. For example I only want to display this "Delete node" field if the logged in user has permission to delete that node. This appears to be handled automatically by Drupal when using the "Node: Delete link" field.
I did manage to get the same effect using a custom field, but to do so I had to create a theme template file based on "views-views-field.tpl.php" and inserting this code:
However, I can't help but feel I am "reinventing the wheel" by hard coding functionality that already exists. Is there some way that I can hook into the function which displays the "Node: Delete link" field so that I can rewrite the output to display an icon rather than text?
.:.
http://css-tricks.com/css-image-replacement/
Thanks for the help, used jQuery for image substitution
Thanks for the help, the css image replacement did the trick. For the benefit of others this is how I did it.
When adding the field (e.g. "Node: Delete link"), I surrounded the field with a "
<span>" element and gave it a unique class name as an identifier. I did this by modify the "Rewrite the output of this field" option on the field configuration page.This way the link to the delete node link will be identifiable by the surrounding "
<span>" element. I tried to add a class attribute directly to the "<a>" element, but could not find an easy solution to this through the field configuration page.Next I used jQuery to add the image to the "
<a>" element of the "Node: Delete link" field when it is rendered in the browser. To do this I added this code to my "script.js" file in my theme directory:For more information on what the CSS is doing see: http://xavisys.com/css-trick-turning-a-background-image-into-a-clickable...
This method of embedding the image relies on the jQuery API, which means you must have it installed in your drupal installation.
While I will not explain how to install th jQuery API in Drupal, one thing I will point out is how to add your custom jQuery functions/code to drupal. For this you need to create a custom JavaScript file in your theme folder (In my case I called the file "script.js"). To add this file to each page on your website you need to adding the following line to the "mytheme.info" file, which is also located in your theme directory (NB: "mytheme" should be substituted for the real name of your theme):
The advantage of method described in this post is that if javascript is not enabled in the browser a text link will still be rendered, so that the delete functionality is retained and still accessable to the user.
Hope this helps others.
_
Surely adding
to your CSS would have exactly the same effect without requiring jQuery...
can someone delete these?
can someone delete these? thanks!
THX ,very smart!
I've spent times to find a solution ,I've tried any possible complex way,but just with simple CSS it's work perfect and without any performance issue!
just a test
sorry
another test
sorry