I put the replacement pattern [view_node] in the Link path field and get href="/view" instead of the path to the node. If I display the Node: Link field, it's displayed as:
Link: view
The word "view" is a link to the node so the field when displayed works but not when used as replacement pattern. The pattern [view_node] result in the word 'view' instead of the path to the node.
My view has three fields:
Node: Body
Node: Link
Node: Title
Defaults: Configure field Node: Title
[x] Output this field as a link
Link path:
[view_node]
Alt text:
[body]
The resulting links all have href="/view". How can I get the href to point to the node?
Comments
Comment #1
merlinofchaos CreditAttribution: merlinofchaos commentedWhen you put another field into a view, you're going to get the entirety of the field. So when you use view_node, you're not just getting the path, you're getting the entire
<a>
tag. This is almost certainly not what you want.You probably want to do it the other way around, where you rewrite the view link output to alter its output to the title and the alt text to the body.
Comment #2
mattyoung CreditAttribution: mattyoung commented>You probably want to do it the other way around, where you rewrite the view link output to alter its output to the title and the alt text to the body
I still have the same problem: what do I put in the "Link path" in the "Node: Link" field? To set alt text, I must check "Output this field as a link". But with this checked, I need to enter the "Link path".
Here is what I did: change the order of my fields:
Node: Body (not displayed)
Node: Title (not displayed)
Node: Link
Configure field Node: Link
[x] Rewrite the output of this field
Text:
[title]
[x] Output this field as a link
Link path:
????? <======= what do I put in here?
Alt text:
[body]
Comment #3
mattyoung CreditAttribution: mattyoung commentedI found a way:
Instead of "Node: Link", use "Node: Nid" field
In "Node: Title",
[x] Output this field as a link
Link path:
node/[nid]
Alt text:
[body]
Comment #4
kthullIs Link path: node/[nid] the only way? That blows the whole SEO friendly url component out of the water.
ETA: Just played around some more with this and for my purposes, I need an image link to point back to the node via a "more info" button. I added a Node: nid field, changed its output to be the html to call up the more info image and checked off the box that says to link this field to its node.
Not exactly a fix, but providing the functionality of the Node: link with [view_node] replacement in a roundabout sort of way.
Thanks,
Kevin
Comment #5
mattyoung CreditAttribution: mattyoung commented>That blows the whole SEO friendly url component out of the water.
Actually no, the link node/[nid] becomes the alias if it has one so no problem for SEO.
Comment #6
tierecke CreditAttribution: tierecke commentedI don't agree with it.
I tried your suggestion a few times, and the link always remained node/[nid].
I wonder how I can get the link without the
Comment #7
mattyoung CreditAttribution: mattyoung commentedI'm not sure how it happens to work for me. It could be because I'm using http://drupal.org/project/globalredirect
Are you using this module? If you care about SEO, you need it. Install it and try again.
Comment #8
merlinofchaos CreditAttribution: merlinofchaos commentedIf using [nid] you need to be sure that Node: Nid is added as a field. Set it to 'exclude'. Make sure that Node: Nid comes *before* Node: Title as they are order dependent.
Comment #9
Jeffsus CreditAttribution: Jeffsus commentedI had this same exact problem, and the suggestion to use GlobalRedirect did the trick. Even though you specify /node/[nid], GlobalRedirect automatically switches that out with the correct pathauto url before it even hits the page.
Comment #10
jayajha CreditAttribution: jayajha commentedWhile I understand the there is alternative of using [nid], should the existing problem still not get fixed? Isn't [view_node] supposed to output correct link? Having to install one more module (global redirect) just to fix this does not sound very appealing to me.
Or am I missing something here?
Jaya
Comment #11
merlinofchaos CreditAttribution: merlinofchaos commentedNo, it [view_node] will contain the text, not the underlying link.
Comment #12
ressa CreditAttribution: ressa commentedI don't use Global Redirect module, but node/[nid] links are still converted to its alias, so the module doesn't seem to be necessary. I am using Drupal 6.14.
Comment #13
houen CreditAttribution: houen commentedIt works fine for me too with node/[nid]
At first I thought it didn't, but it turned out to be because I had forgot the "node/" part - if you miss this it'll just write the node id number
Comment #14
pipsqueaks CreditAttribution: pipsqueaks commentedI had the same issue that mattyoung had and I think that this should be looked at. It would be helpful, at least, to expose the URL to a comment as one of the fields.
The problem is that I was using views to create a list of comments by a particular user and there wasn't any way to link the body of the comments back to the originating comment. The node/[nid] (or an equivalent cid) trick wouldn't work because the URL to a comment includes more variable content than just the cid (i.e. 'forum/politics#comment-767').
I came up with a workaround that may be helpful to someone else. The comment body doesn't have the little checkbox that says "Link this field to its comment". But the comment title does. So I made the comment body come first in the list and set it to not display. Then I added the comment title field, used the "Rewrite the output of this field" feature to refer to the comment body, and changed the label to "Comment". It's a bit of a hack to use the comment title field to refer to the body, but it worked.
Comment #15
dawehnerNeeds review means there is a patch.
Comment #16
merlinofchaos CreditAttribution: merlinofchaos commentedSigh.
It's not possible. [view_node] will contain
<a href="http://foo">text</a>
and when you try to put that within a link the<a>
gets stripped out and you're left with "text". That can't actually be fixed unless you think it's reasonable (and it's not) that we should actually go trying to parse HTML to find the data you *think* should be there. It is there, but not in the way you think it should be. That field provides a LINK to a node, not the URL of the node.Comment #17
pipsqueaks CreditAttribution: pipsqueaks commentedHow about making that optional checkbox "Link this field to its comment" appear in all of the comment fields, not just the title? Or, if not all, at least the comment body field?
In my case, comments don't have titles, so it was necessary to use the truncated comment body field as a link.
Comment #18
cerylio CreditAttribution: cerylio commentedIf you want your Path of the Node, just use the field Node: Path. Make sure you set on: Use absolute link (begins with "http://"). Then you can use the [path] pattern to use it as primary link and put whatever you want behind it.
Comment #19
rickupdegrove CreditAttribution: rickupdegrove commentedI wanted a "Read more..." link in some views feeds I just created.
After trying a everything on this page It was invalid XHTML because of the issue here
I also tried everything at http://drupal.org/node/391250
Several hours later I remembered a site I built a year ago has this feature
When I use Views in D6, In Fields this is what I do...
Add "Node: Link"
In "Text to display:" I use
Read more...
That is *all* I have to do to get SEO friendly "Read More" links in my "Views"
Comment #20
jindustry CreditAttribution: jindustry commentedHere's another method that may output SEO friendly links. I added the Node:path field, selected "Rewrite the output of this field", and added the following in the textarea:
<a href="[path]">[name]</a>
I wanted to link a Location:name, [name], to it's parent node. Remember, token availability is order dependent, so in this case Location:name had to appear before Node:path for the string above to work. I tried #19, rickupdegrove's method, but it didn't seem to work with the dynamic rather than static link text.
Comment #21
tescometro CreditAttribution: tescometro commented#20 using node:path, worked out for me, and works as expected thanks.
I'm really not sure that [view_node] is working as it should.
quote from #16:
"Sigh.
It's not possible. [view_node] will contain text and when you try to put that within a link the gets stripped out and you're left with "text". That can't actually be fixed unless you think it's reasonable (and it's not) that we should actually go trying to parse HTML to find the data you *think* should be there. It is there, but not in the way you think it should be. That field provides a LINK to a node, not the URL of the node."
Actually if I use the [view_node] token in another fields' path, where you'd expect you actually get
this doesn't make any sense to me at all, and surely can't be as intended..see here too http://drupal.org/node/658872, the penultimate comment describes it best I think.
Anyway, thanks to jindustry for an alternative.
Comment #22
maxplus CreditAttribution: maxplus commentedHi,
I also had problems with this.
Now my solution is also to add "Content: Path" instead of the "Content:link"-field.
When adding the token of "Content: Path" to the "read more" path, everything works fine, no Global redirect module used.
Comment #23
Lux Delux CreditAttribution: Lux Delux commentedI can confirm the above works.
Especially if you're using Pathauto.
Just remember, in the 'Content: Path' check 'use absolute URL'.
Then in the field you want to be the link, just put [path]. Works like a charm
Comment #24
pratip.ghosh CreditAttribution: pratip.ghosh commentedFYI, works automatically in Drupal 7, with the [nid] component...
Comment #25
mattyoung CreditAttribution: mattyoung commentedgood thing. will give it a try some time later
thanks!
Comment #26
sharif.tanveer CreditAttribution: sharif.tanveer commentedthumbs up for #23
works like charm
Comment #27
muranod CreditAttribution: muranod commentedThank you #22 and 23! -- This works for Drupal 8 as well.