Score:-1

Show title of a referenced node

ph flag

I have a node type of "Countries" and node type of "Continent". On the "Continent" node type, I created a referenced field of countries (field_countries). On my Countries search views page, this view displays the list of countries and the link to their respective page. Is it possible to show the Continent (field_title) where the country (field_country) is referenced in?

For example:

United Kingdom
https(:)//mysite(.)com/countries/united-kingdom
**Europe**  <-- this is what I want to achieve -->

On my Views page, I tried to:

  • Add Relationship ( content referenced from field_countries)
  • Add contextual filter ID : Content ID then relationship is field_countries: Content

But it didn't work. Any suggestions?

cn flag
What "didn't work"? If you add the relationship, you should then be able to add an additional field (field: title, relationship: country) and get the name that way. Adding a relationship will allow you to add the reference entity's fields in the Views field area.
sonfd avatar
in flag
Based on how you've structured your data, you need a back reference to the parent. Fwiw, and obviously without knowing any of your other requirements, my default approach for this type of thing would be to have countries reference continent, i.e. add a field_continent to the country content type, rather than how you have this. This would definitely simplify this view as you wouldn't need a relationship.
cn flag
What sonfd said - for data structure it often makes more sense for the child to reference its parent rather than the parent referencing its children. Much like how taxonomy hierarchy works. Then when you need to list countries for a continent, it's just a matter of filtering on nodes whose parent field matches a contextual filter for the continent node
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.