0

I have a path pattern that looks the same for two content types. For example, pattern http://my-site.com/x/y/z, for content type 'Article' and content type 'Property'. They follow the same pattern because they only differ in the actual content. The paths are composed of taxonomy items which are the same for the two content types.

So where x/y are the taxonomies called 'categories' and 'types' while z is the title of the content. And both content types follow the same taxonomy group. So only differs in the actual content. One uses generic 'Article' fields while other one uses many custom fields.

My view mostly is defined by the system path node/% but I need to separate them for 'Article' only types and 'Property' only contents. This works for 'Property'. 'Article' based contents are no longer shown by Drupal now.

I have looked into this and this but they somehow use panels and other one is based on blocks and permissions, which is not what I needed.

I can't seem to use panels because I cannot, for some reason, see my view in the contents that can be added. (Most probably because my Views path is node/%). I can only pull those views that does not follow this format.

Is there any other simple way to pull the two types of contents without having to resort to Panels and separating contents by different blocks? Because it is more readable using Views and much lighter and easier to just configure the parameters I think. U reduce a lot of overheads.

Any thoughts?

5
  • 2
    If I understand correctly, yes you can achieve that using views.Go to your views and add an "Attachment" to the 'page' view. Set Filter Criteria accordingly. You can also achieve that using Views Block – Krishna Mohan Sep 11 '14 at 4:55
  • @KrishnaMohan aha, let me try attachment but I think this will work. I've never understood the concept of attachments but let me try will get back with you thanks! – jan Sep 11 '14 at 5:01
  • Create one view to cater for both. Set the display to content, and choose a custom View mode that you create in code or via Display Suite. Then for each of your types go to its display settings and select the fields you want to display for the custom view mode you created. – J. Reynolds Sep 11 '14 at 5:08
  • @J.Reynolds thanks for sharing your thoughts. Can you ellaborate more on the 'custom View mode that you create in code or via Display Suite'. It's quite unclear to me. I already actually created two views, with same path, filtered accordingly but only one content type is being read. Please ellaborate.You kinda sound like you are correct on this but please be specific. thanks! – jan Sep 11 '14 at 7:59
  • @KrishnaMohan i will accept your comment as an answer if you put it in the answer section below. I have done it this way as it is much easier. Thanks again. – jan Sep 13 '14 at 15:20
2

If I understand correctly, yes you can simply achieve that using views.

Go to your views and add an "Attachment" to the 'page' view. Set Filter Criteria accordingly. You can also achieve that using Views Block.

enter image description here

1

Create one view to cater for both. Set the format to content, and choose a custom View Mode that you create in code or via Display Suite. Then for each of your types go to its manage display settings and select the fields you want to display for the custom view mode you created.

To create a custom view mode you can install a module such as Display Suite (install sub-modules ds, ds_extra and ds_ui as a minimum). Then navigate to admin/structure/ds/view_modes/manage and define a new view mode for Node.

Afterwards navigate to the Manage Display tab of your first content type and select tab 'Custom Display Settings'. Your new view mode should be there. Activate it, and then optionally select a layout and re-arrange the fields in that view mode to your liking. If you install ds_extras you can also select to completely rewrite the output on a per field basis.

Do that for the second content type as well, using the same View Mode you already created. It will have different fields, but will use the same view mode.

Lastly, in views select Content under FORMAT, and choose as view mode the custom view mode you just created.

You can now for even more control of your output also add a template_preprocess_node function to your theme's template.php and set a theme suggestion on it to target NODE_TYPE__VIEW_MODE.

To create a view mode in code you can do the following in a custom module:

/**
* Implements hook_entity_info_alter().
*/
function MYMODULE_entity_info_alter(&$entity_info) {
  $entity_info['node']['view modes']['another_teaser'] = array(
    'label' => t('Another teaser'),
    'custom settings' => TRUE,
  );
}

See Drupal 7 custom node view modes and remember to clear the cache.

There are more light-weight modules out there that can create view modes for you, ie. Entity view modes. But with Display Suite you can completely override the field templates and do stuff like embed views within fields you make up etc.

1
  • I'm tagging it useful answer but not implemented it because i don't want to install extra modules just for this anymore. – jan Sep 13 '14 at 15:19

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.