3

I want to create a block view of some content's image field. I am trying to insert current page node id to paths of image links. Because linked page is a entity form and I try to prepopulate node id in one of the field of the entity form.

How can write to current node id to URL with views rewrite results? URL pattern like that. example.com/form?edit[field_whatisrefferaelid][und][0][value]=[currentpagenodeid‌​] Actually I am seraching for current node id token avaible in views block.

2 Answers 2

0

If you have a Contextual Filter in place for Content: Nid that is pulling in the nid from the currently viewed page, can

  • Add a field for your image
  • Choose Image for the formatter. Configure the image style that you want.
  • Link image to Nothing
  • In Rewrite Results, check Output this field as a link
  • In the link path, use form?edit[field_whatisrefferaelid][und][0][value]=!1
  • Check Use absolute path

The !1 is the replacement pattern for the first contextual filter. It should be listed in the list of replacement patterns in the popup you do the configuration from.

That shuld

5
  • but these image are link to a form page and URL pattern like that. example.com/form?edit[field_whatisrefferaelid][und][0][value]=[currentpagenodeid]. In every page last part of url [currentpagenodeid] must be different
    – mtin -nong
    Commented Feb 28, 2014 at 23:44
  • @mtin-nong Sorry, misinterpreted what you needed. Try the new version.
    – mpdonadio
    Commented Mar 1, 2014 at 0:09
  • I think the solition is close but with !1 nor "Output this field as a link" neither "Rewrite the output of this field" options render node id. Also in "Output this field as a link" options square brackets renders as like that %5B
    – mtin -nong
    Commented Mar 1, 2014 at 0:33
  • The %5B is the bracket encoded. !1 worked in the view I tested with.
    – mpdonadio
    Commented Mar 1, 2014 at 1:12
  • !1 works only if images comes from current node and provide default value>content id from url is selected. These images will be use every content in selected content type and must be shown if images are not their node.
    – mtin -nong
    Commented Mar 1, 2014 at 1:19
0

You can simply follow below steps:

  1. Add ID field in your view, hide the display of it and drag it above the image field .
  2. In you image field, link the image to nothing and rewrite the result as below using the {{ nid }} as replacement pattern:
<a href='/form?edit[field_whatisrefferaelid][und][0][value]='{{ nid }}>{{ your image }}</a>

If the image is not part of current node, you can simply use {{ url('<current>')| split('/') | last }} in you view rewrite result as:

<a href='/form?edit[field_whatisrefferaelid][und][0][value]='{{ url('<current>')| split('/') | last }}>{{ your image }}</a>

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.