6

I am displaying some view blocks on a page. The content is being filtered by passing the nid from the url into some custom php. I wish to change the block title to use a field from the node in question. Is this possible?

1
4

For Views 3 , the given answers are partially incorrect. Tokens are allowed in the header area of view blocks. The only tokens available are for the fields used in the view. So you can set the field that will be used only for its token to hide.

You have to select the Global: Text area option in Header, check Use replacement tokens from the first row and select the token from the Replacement Patterns dropdown.

1
  • "Views allows tokens in Header area of the views blocks". Contextual filters are available as well. – Dalmaz Oct 31 '13 at 15:02
2

In the current version of Views (3.14), you can write tokens in the view title.

It doesn't say so in any help messages, but I have tested it on https://simplytest.me and it worked.

You can see the available token names by selecting the last field and activating Rewrite the output of this field and folding out Replacement patterns.

1

I don't believe this is possible from the Views UI.

You could do this by creating the title using [theme_name]_preprocess_block hook in your theme. You might also be able to set the block title in a preprocess hook for the view, but I don't know which one you should use.

1

This is not possible because views doesn't allow you to used tokens.

That being said it is technically achievable. When you say you pass the nid into some custom php. What do you mean? Does the view use the nid as an argument? or are you returning something else.

The real question is are you actually filtering the content by the field? If you happend to be passing in the nid, doing a node load, then filtering on that field then this is indeed possible. I'm just guessing this is what you're doing. I might be wrong.

If you happend to actually be filtering by the field, then when you edit the argument you will see there's an option to override the title. You should be able to use %1 or %2 depending which argument is the field value.

Note I'm making a lot of assumptions on this answer. So again, this is only possible if the value you're actually filtering on is the field.

0

I understand that each views returns a single node displayed in a block and you want to change the title of this block. You could easily do this with a tricky trick :).

  • Build your view with all the fields you need, don't put it a title
  • Select the node title field and select "rewrite output", put the field token in the textarea with <h2>: <h2>[field_FIELDNAME_value]</h2>
  • Don't put a title to your block with <none>

Normally with this you should see your block with the title of the node returning by your view styled like a block title due to the presence of the <h2>, a little more CSS to polish and you're done.

0

It is easy. In the title of the block you only have to add the token, that if, this field obviously must exist in your view, rewrite the field output to be able to get the name of the token and copy and paste in the title of the block.

Your Answer

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

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