Drupal 7: Add view to content type - drupal

I've been making a template for a particular content type, but just ran into a problem: I need to embed a view into the content type.
I am aware this can be done via several different methods, but I don't see one that fits exactly my needs:
I need the view added automatically for all pages of that content type.
Using blocks in a region is not an option, as I want to avoid defining a region in the middle of a page that should only be available for a specific content type.
Translatable label.
Possibility to freely apply a template to all fields in the content type (excluding the embedded view).
I tried doing it via page layout (Panels) and simply adding node content fields and the view to my layout regions, but then I get another problem: I can't style my content fields without doing something that seems a bit over the top:
Currently I have about 20 different content fields in the content type that are wrapped in HTML and styled in my template file. I have a translated label for each of these in the template file. From what I can tell I'd have to add a template for each of the panes containing content fields to add my translated labels and HTML needed to style each field.
I'm not really fond of making 20 templates, 20 theme hook suggestions to get the templates to work and 20 regions in the panel layout just to get a view inserted in the content type.
Am I doing something terribly wrong here? Any suggestions?

You may want to try the Viewfield module or similar modules (search for "view field" or "view reference").
If you are doing something more complex like changing/filtering the view based on some value in your content type, then you may have to use Viewfield module in combination with something else that will help fill in the filter values.
I've never done something like this before so I'm not sure exactly what module combination would work but Rules or Computed Field come to mind as possible helpers.

You have to use "views node field" http://drupal.org/project/viewsnodefield, after installing this module you have to select the "Node content" in the display (like blocks,page). then click the add display. if you want to display the content like this page http://www.richtown.ae/?q=content/arabian-ranches then you have to download the views_galleriffic module and install it and choose the style option "Galleriffic Gallery". You can choose the content type by using the filter in the views.
That's it cheers
i implemented this in my website richtown.ae
if you still unclear please send me the email social#richtown.ae i will reply you & ready to help you we can share information
i am using this module in drupal 6.

I resorted to using the EVA module ( http://drupal.org/project/eva ).

In addition to Woodgnome's answer
Let's say you have a content type named 'Product'
You want to attach a view to it.
Here are the steps using the eva module :
On your view edit page :
Section Displays
+Add : Eva field
Section ENTITY CONTENT SETTINGS
Entity type:Node
Bundles:Product
That's it, going to a node product type will now display the view

Related

Drupal page content

I'm new to drupal and reading through docs, but hoping to get an explanation for something.
I have a page called page--type-home-page.tpl.php.
Part of this page prints render($page['content'])). I want to remove something that is rendered as part of the page content from the page, but don't understand where this comes from and where/how to look.
Thanks!
Assuming you're talking about Drupal-7
Well the $page['content'] contains a string, which is a rendered version of what's injected into the content region of your theme.
By default, the only block in this region is the "Main page content" block that is generated by the Drupal core. Many things can generate this content but it always pass through the menu API. For instance, if you're viewing a node, the URL used is: node/12. The node module declares a menu entry for node/%node, this menu entry contains a callback function that will render whatever the module wants to render. The module, then, may use different strategy to render it's content from a simple function to a complex imbrication of templates.
The key to alter what's in the box, sorry, what's in the $page['content'], is to know what is rendered and to understand how it's rendered.
If it's a node, first you want to look if you can achieve your goal through the display settings of the content type. admin/structure/types/manage/page/display: And this is true for all entities (users, comments, taxonomy term etc.) Because this is the first thing the module of these entities will put together when they'll try to render your content.
If this is not enough to achieve your goal, you can look into the module that renders the path to see if it hasn't a .tpl.php. You'll be able to re-use it in your theme. You'll want to copy/paste the file in your theme and edit it.
If the module do not have a tpl file to override, try a template suggestion: here's a list from Drupal.org
Ex: node--type.tpl.php
If all this doesn't satisfy your need, you'll have to dig into preprocess functions; Those functions allow you to modify what's in the variables passed to .tpl.php files. That's a little more advanced and I recommend you to read this previous stackoverflow question/answer
Simply, don't use that $page['content'] which prints all content, but place your custom template code instead and print separate field values where you need them like:
<?php print render($content['your_field_name']); ?>
https://drupal.stackexchange.com/questions/30063/how-to-print-fields-in-node-tpl-php
If you want to do just simple styling, like excluding some field you can use content type display options like mgadrat explained, but if you want to use some complex styling, with totally custom html this solution is easier.

How to "separate" image uploads while using multiupload image field

My client has a bizarre request which is making it difficult to build a slideshow on profile2 pages: The profile2 pages require 4 photos to be uploaded, and he does not believe that the users adding content to the site will "get" the multi-select method found in most file upload modules. The Field Slideshow module only works if you're using multiupload (which of course makes sense), and that's how I had it set up initially - which worked perfectly. I've tried using the field collection module, then creating a Slideshow view, but the image fields in the field collection field aren't being seen as a group. I think I had to select one of the 4 image fields to use instead of all 4. Any ideas?
he does not believe that the users adding content to the site will "get" the multi-select method found in most file upload modules
This hardly makes sense, I guess you tried to explain things to your client ?
Assuming you have several image fields on your content type, you could build a view which create a list (unformatted or HTML list) of these fields, maybe using a global field rewriting (you add all your image fields, exclude them from display, custom their display by removing field wrapper and field+label wrapper (in order to get only ), add a global text field in which you include image fields token), and then create your slideshow in a custom javascript file, using whatever library you like (Cycle2 is great).
Your global text field would look like :
<div class="wrapper cycle-slideshow">
[field_image]
[field_image_1]
...
</div>
(with cycle2 adding a cycle-slideshow class will initialize your slideshow)
...but you need token to do so.
I often find it more convenient to setup javascript things like that (slideshows, gmaps...) by myself instead of using views integration.
Hope I understood your issue correctly, good luke with this.
For every (custom) field you have option "Number of values" which you can set to fixed amount (i.e. 4) or unlimited. Can you use that?
Easier: Use Rules. Create an additonal (fifth) image field (multivalued) that will be the one consuming the slideshow. Create a new Rule, triggered on creation or update of your content with 4 actions: each one adding the content of one of the fields to the multivalued field list. You probably need to avoid showing that field but that depends on what are you using to display, so hide it using display suite or just not using it in the content template. This way, you show your users your 4 fields but makes the slideshow work based on a computing of the user inputs.

Custom spaces editable from back office in Drupal

I've got a website in Drupal where in some parts of the site I need some editable spaces to put some banners and edit them from backoffice, (something similar to placeholders in Django).
Is there any module or a way to do this?
Thank you!
There is the block module, which is part of core. Are you using Drupal 6/7/8?
Anyway go into your admin section and look under structure, for blocks.
You can create custom blocks and place them in a region. If you want different regions then you can define these in your themes .info file.
Inside the blocks you can put whatever content you like.
Than you for your help , this did the job:
< ? php
 $block = module_invoke('block', 'block', 'view', "23(block number)"); 
 print $block['content']; 
? >
So, to create a custom (static) block you should go to "Blocks" admin page (Structure -> Blocks) and click "add block page" link. When creating the block pay attention on input format field (bellow "block body" field). If you use some format with filters drupal can (partially) destroy your block code - filter out some content. So, if you are sure that code you are using is safe and don't want it to be changed by drupal select "raw" format.
Every theme has defined regions that it supports. They are defined in:
/sites/all/themes/theme-name/theme-name.info file
So, if you want to change page template and print blocks on your own you must use some existing regions, defined there (it's needed to clear the cache after changing this file).
Region names can also be seen in Blocks admin page mentioned above. On that page you'll see the list of all available blocks and next to block name you'll see drop-down for placing block into some region.
Also, if you edit some block (click "configure" link next to that drop-down) you'll have some extra options to set block visibility (per user, per user role, per page..).
For more advanced block placement use "Context" module which have more powerful features for placing blocks and more:
https://www.drupal.org/project/context

Different pages for showing different fields of a single node in Drupal 7

Is it possible to elegantly do this? The idea is, a node of content type "project" has a lot of fields, its url is something like node/5. I want to show some of the fields on that page, and others on node/5/extra, kind of an "extended" page that the user only loads if he is interested in that content (lots of images, in my case, that would slow down the main node page considerably).
I tried the Display suite module, unsuccessfully (it seems it's not really meant for doing what I want). I also saw this blog post, which explains how to add a custom display mode to a content type (other than the Default and Teaser ones that come by default), but I can't get it to work the way I want to either.
I guess you could create a view having the node ID as a default argument from URL. Then you can choose which fields to show or hide

drupal replacing default nodes with views page

I have created a page view using field style to display a list of teasers as I want. fields configuration in views allows us to link the field to it's node. but what if we have created view for node detail page and want field to link to it's relevant view.
I had the same question, and after a bit of research this is what I've concluded:
The views module isn't intended to replace a default node view. I say this because of the level of difficulty involved in doing this and the lack of information on how to accomplish this. Ryan Weal has posted a way to accomplish this by editing your node template that doesn't look too difficult to accomplish, and here is the link.
However, it seems that a more popular solution, especially if you are like me and don't like to get into editing theme files. You can use the Display Suite module to effectively reformat the default node content as you would like.
I'm not sure if I understand you properly, but it sounds like you are wanting to display a view in a page view of a node?
In order to do this, you could:
create a small module, using hook_nodeapi() or one of the D7 replacements for this function in order to insert the output of the embedded view into this page's content, by conditionally adding a $content element when the node is of the appropriate id
or (easier, but requires allowing input type PHP) embed the view right on the page.
http://thedrupalblog.com/embedding-view-drupal-6-using-views-embed-view for information on embedding views

Resources