1

I have created a View (for /blog). The blog page is just articles grouped together. Underneath each blog post I'd like "Comments (x)" (x = showing the number of comments).

That part is done, using Rewrite results > Output this field as a link. Link path = blog/[title]#comments

What I would like to do now is when there are no comments, have a HTML link "Comments (add)" which goes to the comment form for that blog post. E.g. blog/[title]#comment-form

Problem:

I haven't been able to create the "Comment (add)" HTML link using No results behavior > No results text (Is it possible?)

I've tried:

<a href="/blog/[title]#comment-form">add</a>

and many other alternatives. The link becomes

/blog/%3Ca%20href=

Am I on the right track? How do you recommend I go about this?

2 Answers 2

1

You may want to investigate Page Manager (Ctools suite). This module allows you to intercept a URl and create variants based upon conditions (contexts) from the URL call. Page Manager works very well with Panels which allows you to break down regions in your them into subregions and insert views in the panel. Panels is fairly easy to use and even if you do not want to include additional sub regions, it combines well with Page Manager to accomplish what you want. You can find more on how to use Page Manager at nodeone.se

By way of an example you could create a panel page using Panels or Page Manager (it works the same starting in either module). If the path were /blog/%blog then the page definition will intercept all /blog/anything URLs. You could then create two variants, one to act if there are no comments and one if there is. You would then add a layout and include a view for each one.

Another approach might be to use Page Manager variants to redirect a URL request to another location so one could call the View directly and the other could go to the comment form.

1
  • Thanks very much Ashlar for the quick reply! Will do and report back! :D
    – Nick
    Commented Apr 6, 2012 at 20:24
1

I solved it! Using a simple method I discovered within Views!

In Views > YourView (Page) > Fields (Make sure you have the following fields)

  • Content: Nid (In it's properties, select "Exclude from display")
  • Content: Comment count

I discovered that when you add another field (e.g. Content: Nid) it becomes available in the Output this field as a link > Replacement patterns for all fields! Sweet!

What I did then was (Modifing Content: Comment count)

(Show the comment count, and turn it into a link)

Rewrite results > Output this field as a link. Path= blog/[title]#comments

(If there are no comments, add a HTML link with a link to the Node's ID comment field)

No results behavior: (<a href="http://www.yourwebsite.com/comment/reply/[nid]#comment-form">add</a>) Comment

Hope that makes sense! :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.