1

In views, when using the standard text formatter you can place replacement tokens such as [title] into the HTML code either in a rewrite or in this case global text for Drupal to render.

In this case I have a node field with the Machine Name field_story_url that is used within a view. Part of my PHP function requires me to define the content found in that field so I do $urlhere= '[field-story-url]';within a Global Text header using the PHP filter input.

But it does not work. I then did a simple <?php echo '[field-story-url]'; ?>to see if it would print the value and nothing either.

When I did the replacement using just HTML it worked. Anyone know what the issue may be?

  • I don't believe $node is not available in Views, even if it was, it would represent the View as a whole, not the results in a Global Text - since it wouldn't know which row you are trying to access – Geoff Apr 23 '15 at 21:29
  • So what would we use? The replacement pattern views shows is [field_story_url] so what does views use to render that? I tried the $views and $handler prefixes but no luck. – user12342 Apr 23 '15 at 21:37
  • there is an option "Use replacement tokens from the first row" in the Global Text overlay which is probably selected, which is why replacement tokens are appearing, so as long as the field appears in the first row, it can be pulled to show in the Global Text, but it should only be that one row value. Assuming you have a view that lists 50 nodes in rows, are you trying to show 50 field-story-url values in the header? What is the purpose of showing the field? – Geoff Apr 24 '15 at 1:19
  • I don't believe tokens can be used in php in Views. They are rendered after the php expression, meaning they would hold no value when the php executes. You can use the Views PHP module to assign fields to variables which can then be processed via php, but there might be a better way - but you haven't yet explained the purpose of this, giving people context for the question, in order to more easily help you accomplish what you want – Geoff Apr 24 '15 at 1:39
0

Figured it out. When using replacement patterns within the PHP filter you simply use double quotation marks over single ones.

i.e: $urlhere= "[field_story_url]"; over $urlhere= '[field_story_url]';

Looks like the double quotes is what allows Drupal to see the replacement tokens outside of the PHP code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy