2

I am working on Drupal 8. I have a to display content from a content type on different pages. I am trying to use Views to achieve this.

In the content type I added a field to refer to Pages so that I can create relation between content of content type and Pages (another content type). Basically its like tagging content with page name.

I want to display content from content type created on those pages tagged in the content. I am not able to achieve using views.

Any ideas how this can be done? I have tried contextual filter and relationship but none works.

Thanks

1
  • Welcome to Drupal Answers! So, basically, you want to a page showing those nodes for which the reference field points to a page with the same page title. Did I get it correctly?
    – apaderno
    Jun 23, 2016 at 6:42

1 Answer 1

0

You can use as an example the taxonomy term view, which is in the D8 standard installation:

admin/structure/views/view/taxonomy_term

Two steps are necessary. First define the parameter in the path. For the taxonomy term this is:

Path

taxonomy/term/%
 ‎
This view will be displayed by visiting this path on your site. You may use "%" in your URL to represent values that will be used for contextual filters: For example, "node/%/feed". If needed you can even specify named route parameters like taxonomy/term/%taxonomy_term

Then add a contextual filter in the advanced section, which will process this parameter:

CONTEXTUAL FILTERS
Add contextual filters
Content: Has taxonomy term ID

For the details see the example in your drupal installation. In your case you would use the referenced Pages node id.

If you want to use the view as a block, you cannot define the parameter in the path setting of the page. Then you have to switch in the contextual filter to "Provide default parameter" and configure the parameter from URL.

5
  • If I get what the OP is saying, the difference is that for a vocabulary, there is just a single taxonomy term with a given title. With a content type, you can have different nodes with the same the title.
    – apaderno
    Jun 23, 2016 at 6:44
  • I don't see title mentioned in the question, but the URL should always match a single node, even if there are different nodes with the same title.
    – 4uk4
    Jun 23, 2016 at 6:57
  • The OP says Basically its like tagging content with page name. Since the OP uses page to mean a content type, I take page name is the node title. The difference is between nodes and taxonomy terms, though.
    – apaderno
    Jun 23, 2016 at 7:23
  • In this case the example taxonomy term should lead in the right direction. You should make relationships with entity references, if it is a term or a node. Not with the title, because this is not unique and if modified you loose the relation.
    – 4uk4
    Jun 23, 2016 at 9:06
  • I don't mean the answer is wrong. I just mean there are probably some differences the OP should know of.
    – apaderno
    Jun 23, 2016 at 9:07

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.