0

I have a block listing nodes that all reference the same 'parent node' (etity reference). I would love to see the title of the referenced node as a title of that block.

Example: on a record label website there could be nodes for albums. Every album node references one artist. On an album page there would be a block listing "Other Albums of Artist XY".

I know my question is quite similar to this question "Dynamic block titles" but the solution on that question suggests using Tokens in the block's body, along with some h2-tags, so that it would look like the block's title.

Sounds like a swell workaround – however – since the block I use comes from a view, there is no body I could place tokens in.

Another workaround that almost did the trick was to add the referenced content type to the fields of the view, hide the output, then use tokens in the header of the view (again with h2 tags). But I only could get the referenced node fully rendered, making it impossible to use as a fake block title.

How can this be done? I would gladly welcome any hints and/or pointers…

Thanks! t.

3 Answers 3

1

Add the content title a second time, but this time set the relationship so that the artist's name is displayed. Set the display of this title to hidden, and make sure it has a label which reads : 'Other albums by'.

Then in the Format section, select settings, and then group by this artist title field you have just added and hidden.

The title will get wrapped in an h3. If you want to wrap it in an h2 then you will have to override the views template, one of the suggestions in the Style Output of the provided theme information.

3
  • Thank you, but as far as i can see this is exactly my setup – but since it's the referencing content type nid, I consequently get the title of the current page; Following the above example this would be "Other Albums of Ablbum A". Commented Aug 8, 2014 at 13:28
  • Updated my answer. I now see where I misunderstood you. The answer is more of a workaround but I have tested it and it works. Commented Aug 8, 2014 at 16:00
  • I'm sorry, but I have to say I only partly understand your answer. I think the first half is what I have also in my view – but I have difficulties understanding the second half: how can you first set the display to hidden and then again show it grouped under the Format section? However – I finally figured out a way to achieve what I need and will post my own answer here… Commented Aug 10, 2014 at 10:46
0

After a couple of days of tinkering I finally found the solution – and I think it's a good idea to document it here in case somebode else needs a similar setup.

First under "Fields" I added the referenced node by adding the result of the entity reference field I want to display in the block title, e.g. related band (parent of album) –– and set it to hidden ("Exclude from display").

Now the result of this field is available in "Header: Global: Text area" as a token. Checking "Use replacement tokens from the first row", selecting the correct token and adding it to the header text field above.

This makes the content of the related node available – and actuually I get the full content of the node, all displayed in the header region of the block. This is nice, but too much.

To limit the display to the headline only, I first installed the module https://www.drupal.org/project/token_filter – this adds "Tokens" to the pulldown "Text format" underneith the "Header: Global: Text area".

Next step was to add a small function to the template.php that will add functionality to use individual templates for every Text format separately as described over here: http://fredparke.com/blog/using-custom-template-files-different-display-modes-drupal-7

And this is the function:

function THEMENAME_preprocess_node(&$vars) {
  // Custom display templates will be called node--[type]--[viewmode].tpl.php 
  $vars['theme_hook_suggestions'][] = 'node__' . $vars['type'] . '__' . $vars['view_mode']; 
}

Now I can add a template named like this: node--artist--token.tpl.php and through this I can trigger, how the artist page is displayed, when loaded as a token. In my case: adding and some classes to the title did the job.

There is probably easier ways to do this – but this way gives me 100% controll of what is displayed – and how and where… Hope this helps somebody someday.

0

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

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.

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.