I have a content type which has a Entity Reference field (field_industry). I am trying to create a menu on a page containing all the nodes which have an enity reference which is the same as the title or URL of the page the view will be displayed in.
EG
I have a page called glass, and 2 pages below which have the Entity reference of "Glass". I have created a view, which shows the title field. If i add a field to the view (field_industry) and set it to =glass. But it needs to be dynamic. How would i do this with "contextual filters"?
The entity reference field stores a reference to the actual node so you do not filter on the string glass you filter on the node id.
If my understanding is correct when you view the glass node you want to show a list of all nodes that reference the glass node.
Create a view showing content of the type you want to display, also create a block with that view.
Add a contextual filter on the field that is used to reference the material.
For "When the filter value is not available" check "provide default value" and then "type" should be "Content ID from URL"
Go to admin/structure/blocks and place the block where ever you need to display it.
Related
I have 3 Content Types: Restaurant, Menu, and Menu Item.
I've set up my Restaurant content type so that when a 'Restaurant' is created I have the ability to create a Menu with Menu Items, using the Entity Reference and Inline Entity Form modules. This is all working well.
The part I can't get to work is to display the Menu items correctly in the 'Restaurant' page.
I created a Menu View block, where I added Menu Item fields, and filter it by Content Type 'Menu Items'.
When I place this block in my restaurant page, I see all menu items being displayed...
How can I display only the Menu Items that are related to the Menu content type that related to the Restaurant being viewed?
Edit:
In my 'Restaurant' content type I created a field_menu which is an Entity Reference to the Menu content type, and I use the Inline Entity Form module to allow the creation of 'Menu' entities within the 'Restaurant' creation page.
Similarly, in my 'Menu' content type I have a field_menu_item which is and Entity Reference to the Menu Item content type.
In that case you should add the relationship between menu items and restaurants in order to access the field menu in the menu items view. You can do this in the Advanced area relationships and add the entity references that you need. In your case you should add the menu referencing field and the restaurant referencing field. They should appear similar to
Entity Reference: Referencing entity
A bridge to the Content entity that is referencing Content via menu_item_field
All the above should result in the appearance of the menu field in the filters of the view. When the menu field will be accessible in the filter of the block view you should add a contextual filter for that field.
Then in your contextual filter in the "When the filter value is NOT in the URL" area select "Provide default value" and Type "PHP code" (You should have enable php filter for this). In your php code area you should have the following code
$node=menu_get_object();
return $node->field_your_machine_field_name['und'][0]['target_id']; // this is the field you will use for filttering.It should be the menu field in the restaurant content type
Hope i didn't confuse you. It's not a simple task though.
Let's say I have a content type of "person", which contains details about that person. I have another content type of type "house", and I want to use an entity reference field to select different people, but when the content type is displayed I want not just the person's name (the title of the referenced node) but all the other details. I have tried selecting the View mode "Rendered entity", with view mode "full content", which I would expect to display all the fields - but I can't get it to work - it just displays the title.
Have you set up the full content display to display all fields?
Go into your person content type - go to custom display down in options.
Then up in the top right corner you should have default, teaser, and full content links.
Go into full content and make sure all fields are being displayed.
I created a content type a while ago, and a view to filter it. I just added a field to that content type. When I try to add a filter to the view, the field that I just created isn't in the list. If I create new content of that type, I can see the new field, but not from the view. I deleted and recreated the field, changing the type of field, and have cleared cache. I've also tried creating another view, and still can't see that field. I can see all other custom fields, though.
Is the field you added a taxonomy or node reference? You may need to add a relationship to the referenced entity in order to get it to show up under the view fields.
Click "Add" beside "Relationships", and see if the entity type you are referencing is in that list... add the reference, then go back to adding fields and see if it shows up in your list.
I have successfully created an Entity Reference as one of my content type fields. I am using the Select List as my widget type. The content of the Select List defaults to the node title. This is problematic in my case and I would like to display different field content of that node. Anyone know how to do this?
When you create an entity reference field in the field settings you can specify that it uses an "entity reference view" to create the list of options.
So in Views, create a new view that outputs the field you want for the Entity type you want. Set the display type to be "Entity reference" (you may need to install the Entity Reference view Widget module)
then in the the field settings for your field set it to use that view.
I developed a content type of "sale car". Now I'm developing its view to display a brief list of Car Ads with some basic fields (car, model, color, price, link to full ad) inline of each other like this:
BMW, 120 d $X,xxx,xxx.xx
Royal Blue, Automatic, View Ad
I'm wondering how can I achieve this style? What style format I should use: Table, Grid or something else? Or do I need to get it done through coding?
You want to create a view that is a list of fields.
Once you've got this, add the relevant fields into the view and you should be done.
Choose the relevant format from the format link, check the preview and you should have your view.
To create the view structure:
Node 1 Node 2
Field 1 Field 2 Field 1 Field 2
Field 3 Field 4 Field 3 Field 4
Add all four fields to the view. On each one select "exclude from view". At the bottom of the field list, add a new "custom text" field.
Do exclude this one from the view though, that's important.
Go into the custom field and in the textarea you can enter HTML code and use the replacement patterns to output the field.
For example:
<h2>[title]</h2>
<ul>
<li>[field_one_name]</li>
<li>[field_two_name]</li>
</ul>
<ul>
<li>[field_three_name]</li>
<li>[field_four_name]</li>
</ul>
Get the name's from the Replacement Patterns box under the textarea.
Then select whatever format you think is right. I think you're after a grid.
Drupal provides a way to style the view.
Go to your view.
Click on 'Advanced' link at right side.
Click on link after the label 'Theme'.
You will get the list of templates used to style the view.
Create your own template with one of the given name in the list for
specific fields. e.g. views-view--VIEWNAME.tpl.php
You will get the view of your own style.
This is how the Drupal views styling works. :)
Styling views in Drupal 7:
Add field(which to display) and check the option "Exclude from display".
Now go to "Rewrite Results" and check the option "Rewrite the output of this field"
and below there is a section called "Replacement patterns" where all the added
fields appear as a variable(saying variable just for easy understanding)
Like :
[title] == Content:
Title[field_event_date] == Content:
Event Date[body] == Content:
Body[body-value] == Raw value
Above there is a text ares called "Text" where you can customise your style
for this field(Not good practice follow step 4 for better)and clicl "Apply All".
Now add one more field(this is an extra field) called "Global: Custom text"
DO NOT check "Exclude from display" and below text area called "TEXT"is
the area where we will be writing our HTML codes for styling the views
using all the fields which are avalable as token here under the option
"Replacement patterns".
Click on the "Apply All", And YES its done.So simple and cool na??