I'm using a view to create a list of images that should have only fragments in the href attribute like this:

<a href="#products"><img src="xxx"></a>

But in the "Link path" field of "Output this field as a link" there's only two options as described by the help text:

The Drupal path or absolute URL for this link.

I want to add fragments *only*, but that's not possible in the "Link path" field, right?

To add a fragment there would have to be a separate field like alt text and target, right?

I've read #399534: Add fragment and query to render_as_link but that wasn't not for "Output this field as a link" if I understood it correctly.

CommentFileSizeAuthor
#6 views-738172.patch571 bytesdawehner

Comments

merlinofchaos’s picture

Status: Active » Closed (works as designed)

Unfortunately at this time, fragments can not be placed in Views' linking mechanism.

AdrianB’s picture

Ok, thanks for the answer! It was what I expected from what I've tried so far, I just wanted to be sure.

merlinofchaos’s picture

Category: support » feature
Priority: Minor » Normal
Status: Closed (works as designed) » Active

Atually, I'm wrong. You can use fragments. What you currently cannot do is have fragment only, since trying to put just, for example, "#foo" as the link will try to link to /#foo. Perhaps we can assume that a link that has a fragment and no path should go to the current page.

AdrianB’s picture

Yes exactly, it was the *only* part I was asking about.

My workaround was to specify the complete path like about#[replacement_pattern] to achieve http://example.com/about#products. That is working like it should. The drawback is that the view is not generic, I have to create additional displays for other paths (or perhaps use some other clever replacement pattern magic if possible).

Perhaps we can assume that a link that has a fragment and no path should go to the current page.

That would solve my issue, I don't know if it has any drawbacks though. (What if you actually want /#foo? I guess <front>#foo would solve that.)

myxelf’s picture

Subscribing...

dawehner’s picture

Status: Active » Needs review
StatusFileSize
new571 bytes

Here is a patch for it

myxelf’s picture

Agghhhh! I was working on a patch to address this issue (well at least an attempt, the very first one)...

Anyway, the patch works for me...

Thanks a lot!

dawehner’s picture

If you susbcribe, but you mean you want to do something you could also assign the issue.

myxelf’s picture

I supposed that assigning issues to myself should be authorized by some project-more-important-person. I never thought you were going to move that fast! Thanks for the advice.

merlinofchaos’s picture

Actually it doesn't. We do have the problem of people assigning to self and not following through, but it's perfectly legit (and a good idea) to say "I'm working on this!" and if too much time goes by we'll ignore it. But in the short term it can prevent what just happened.

That said, I do not want to criticize you at all, because, hey, people writing patches is a good thing. Please continue! =)

Also, thanks for testing it. That helps.

myxelf’s picture

I would like to know if there is anything else that can be done to get this commited.

Thanks

merlinofchaos’s picture

Status: Needs review » Fixed

Committed to all branches.

AdrianB’s picture

Thanks dereine and merlinofchaos!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.