Do Views Attachments require changing the Drupal templates - php

I've created a drupal views Attachment display that lists a bunch of nodes. How would I add this to a content type? I've seen examples that require changing the template files, but can views Attachments be used without making changes to the theming layer?

Views attachment displays attach the display to another display within the same view: look at the Attachment settings block on the attachment display. The use case for this is if you had, say, a summary view and a detail view that had to appear together: you'd attach the detail view display to the summary view display.
If you want a view to show up on pages other than the view itself, you need to create a block display. Then, you have two choices:
If you want it to show up in a region defined by your theme (i.e. as a regular block), just go to Site Building -> Blocks and move the newly created block to whatever region you want.
If you want it to show up as part of a node, you need View Reference, which creates a CCK field that lets you select a view. That field can be positioned anywhere in your node template like any other CCK field.

Related

What is the best way to create page in Drupal 8 so that I can then add these posts with images?

I have a Home page on the Drupal website (such as is created after installation), but I still need to create this page:
What is the best way to create a page so that I can then add these posts with images?
I am just starting to learn Drupal and have heard so far about such ways of creating pages:
1) in admin toolbar: Content / Add Content / Article
2) in admin toolbar: Content / Add Content / Basic page
3) in admin toolbar: Structure / Views / Add Views
Which one should I use? Or maybe there is some other option that I don’t know about?
P.S. At the moment I am more interested how to create empty page on which I can then add posts later, and adding posts it is another question.
Welcome to Drupal.
Drupal ships with the default theme which won't look nice but it does its job in the right way. Now if you want to create a better UI/UX obviously you should create a new theme. But before that make sure to read and understand the concepts behind Drupal. Drupal docs are your first friend.
Drupal Documentation
Drupal considers everything as nodes and that's how Drupal got its power. As you mentioned, Articles, Basic Page etc are called content types and they can be used to create a particular type of content.
Now for your purpose create a new content type and add the fields you need. From the image above I can say your content type needs Title, Image, Category and Date. After creating content type you can create as many contents as you want under the content type you just created. Consider each card in your image as content.
Now you can use a Drupal Core Module Views, to perform DataBase Operations without writing single code. Yes, you can select fields, sort, order etc with Views UI and display it in a page or a part of a page (Block).
I would say just try this out in the default Drupal theme and when you understand how this works, you can start creating your own theme for your project.
Theming Drupal
There is a lot of resources available. But you have to make sure what you are asking is whether you actually need. It will take some time, but it worth.
To build layouts for homepages on Drupal 8 you best friend is https://www.drupal.org/docs/8/core/modules/layout-builder
To build the content blocks inside your home page, you should start creating nodes on a node content type to hold your information. For instance: news content type, with a title, a body, a date, and an image.
For every node type, ex. news, work on the preview display, full display, and any other display which makes sense. These displays can be used later in the Layout Builder directly or in Views, referenced below.
If you wish your list to be dynamic, such as the last 10 entries are shown first, then use a view to hold the content sorted and filtered as you need.
In a nutshell.
Create a content type for your article/news.
Modify the displays of the content types to have at least a summary and full view.
Create the content itself to have something to see.
Create the view (block) to filter and sort your content.
Create a page layout (this makes sense for landing pages) which places your new view and any other content you need in any disposition.
This is roughly what I would do. The steps described above contain many intermediate steps. If in doubt, check the docs.
I hope that helps!
First, decide what will you display on that page. Is it content in some existing content type (article maybe) or you want to crate new one for this purpose.
If you need new one then create it (Structure -> Content types -> Add content type).
Then check what fields will you need. I.e. image, some description text. Add missing ones.
Create few nodes (pages) in that type so you could work with them.
Then for displaying you should crate a view (Structure -> Views -> Add view). It can be a page view (you are displaying only that content on page) or block view (this is just a block among some others). If you create a page you could visit it and if you create a block you have to add it to some region to appear on page (Structure -> Block Layout).
Inside your theme you should create templates for this page/block. Turn on twig debug mode so it will show you hints - what templates are used and how can you name yours to override default ones.
Adjust CSS to make it look like you want it to look.
Find some tutorial(s) for the details
Previous answers have given the flow of the work you should go through, I would like to add some resource that might help you achieve this.
Creating content type and fields: https://www.drupal.org/docs/administering-a-drupal-site/managing-content-0/working-with-content-types-and-fields
https://www.drupal.org/docs/user_guide/en/structure-content-type.html
View and View modes: https://www.drupal.org/docs/user_guide/en/views-concept.html
https://www.drupal.org/docs/8/api/entity-api/display-modes-view-modes-and-form-modes
Handling block of the view: https://www.drupal.org/docs/8/core/modules/block/overview
Feel free to ask if any further explanation is needed.
Thank you

How to add custom field to Basic page with particular node ID?

In Drupal, I would like to add a custom field to Basic page content type, but only to one Basic page with a particular node ID.
I know I can add custom fields to the whole content type but this is not what I want.
For example, is it possible to add a file upload field only to Basic page with node ID of 5?
Using Views you can create the list of nodes that you would like to display on the page. The new version of views makes it super easy to do that. From there you have a couple options, depending your level of skill with theming and how much control you need to have over where the list of nodes displays:
A Block - Create a block display for your view. Place the block in the same region as the main content block.
node--NODEID.tpl.php - You could add a template suggestion to your theme to override the specific node that you want to add the list to. To do that you would need to:
Create a node--NODEID.tpl.php file, replacing the NODEID with the nid of the node you want your list of nodes to show up on.
Embed your view in the node template using the following code:
nid); ?>
Where MY_VIEW is the machine name of the view you created and MY_DISPLAY is either "default" or the machine name of a specific display in your view.
Here is an example: http://api.drupal.org/api/views/views.module/function/views_embed_view/7#comment-32858

how do i filter out content from a default Drupal View, based on what content is pulled into the attached view?

currently:
i have a page view that is displaying all content that is flagged as "not featured" with a simple CCK dropdown.
the attachment to the view displays all content that is "featured" and is styled to be a little more impressive.
what i'd like to be able to do is have a few, say 3, featured items display at the top in the attached view, and display all content, whether featured or not in the view below, excluding the 3 displayed in the attachment.
what would be the simplest way to achieve this using the Views UI and perhaps a custom module or two if neccessary?
i'm using Drupal 6 and Views 2
There are multiple ways of doing this. Here are some alternatives
(Using your approach) My understanding is that you are using a CCK Select list field (lets called it FState) which has a state "Featured". Essentially you need to show items that are featured in the attachment display and show items that are not featured in the page view.
In the attachment view you should add a filter which will be Content: FState = Featured. You can do this by choosing the Content group in the Views filter drop down. Choose Content: FState (field_fstate) - Allowed values. Select Featured. Make sure the operator is is one of
In the page view do exactly the same thing except make sure the operator is is none of
If I were to do this myself I would use a nodequeue module ( http://drupal.org/project/nodequeue ) for featured content. For my attachment view I would ensure that the items were in the nodequeue and for the page view I would ensure that the items were NOT in the nodequeue (using the correct filter). There is plenty of material available on the internet on using nodequeue and integrating them with views.
Another alternative is to use the Flag Module ( http://drupal.org/project/flag ) though I suspect nodequeue will be a better match for you.
Edit:
Based on your comments I understand your requirements better. Perhaps you are mixing some language together that can be potentially confusing to an outsider. When you say "featured" content, that means that the content is shown specially. So it is confusing, perhaps, when you say that "featured" content also appears in the page view along with unfeatured content.
Anyways in summary here is what I understand what your requirement is now (continuing to use "featured" in the way you mean it)
You have two views: An attachment
view and a Page View. The attachment
view is a little bit more
attractive.
A news article that appears on the attachment view does NOT appear
on the page view
Lets say the attachment view has space for 4 articles
Occasionally you mark articles as "featured". The 4 latest articles
that are "featured" appear in the
attachment view. On the page view,
all news articles are also shown in
chronological order regardless of
whether they had been marked as
"featured" or not in the past. The only condition
is that there should be no
repetition between the attachment
view and page view.
There is a slight doubt in your specification....forget about your CCK select field for a second. My question is: Do you want to (a) Simply show the 4 latest "featured" articles in chronological order in the attachment view or (b) Do you want to explicitly determine the items and their order in the attachment view?
In case (b) you can have the luxury of choosing an article that was perhaps 1 month old because it was a spectacular article and you still want to keep showing it. In (a) you don't have that flexibility. As new "featured" articles are made, the old ones move out from the attachment view.
Of course for cases (a) & (b) the articles that are shown in the attachment view will not appear in the page view (this should always holds true).
For case (a) you should use nodequeue module for the attachment view and for case (b) you can continue using the CCK Select list method to pull out featured articles as you do currently for the attachment view. To prevent duplicates appearing in the page view use the http://drupal.org/project/views_unique or http://drupal.org/project/views_exclude_previous modules

how can I output the link or path with drupal views and customfield?

I have a view which lists some nodes and I want a custom output for the title of the node. Im using customfield which allows me to write PHP code but I cant find how to output the link to the node? It doesnt appear in the $data object. I can add the field, but still cant use it in the customfield code
Rather than using Views Custom Field to load PHP into the database, consider modifying the views template for the title field. If you go to Theme Information, it'll give you the file hints for the field. Create the file in your theme, and modify the title that way.
This has the benefit of separating code from content, and if you do it this way, you can add the Note: Link field, exclude it from the display, and use it in the Title template you created.
Check out Group 42's Guide to Theming for more information.

How to place multiple content types on a Drupal page?

I've created a new content type called Homepage, which has a number of fields. The fields are node references to the Single Image Promo content type. Single Promo Box has fields for title, text and image. The idea is that I can create multiple copies of a Single Promo Box, each with different field values. I then want to place a few of them on the homepage.
So I can place a specific Single Image Promo on the homepage fine now. But what template file do I need to create to style the way Single Image Promo is shown when it's a node reference on the homepage?
Thanks,
Maria
It sounds like you are over complicating things.
If you want to create some different boxes on your homepage, using node reference is not the right way to go about this. There are some few different ways to do what you want, the easiest i probably to create a block view of the node you want to display. When you turn a node into a block, you get the ability to place it in any of your theme's defined regions.
You could also just create a view and from there get the different Single Image Promo you want without using node reference at all. Views has a lot of different filters, which will enable to you create a view that always displays the right nodes. This solution wont work well, if you want to place the nodes in different regions though.
To answer your question, when nodes are being displayed, they will by default be rendered with the node.tpl.php template file. To make specific templates for each of your node types, you can create a new template named node-nodetype.tpl.php, where nodetype is what you called the node type when you created it.
node-nodetype.tpl.php can work to a certain degree, but in that file you are styling the entire page, with the content type's fields delivered wholesale to the tpl via a single $content variable. Maybe it is enough for you, but if you need finer grained control:
You can edit and style the individual content type's fields with the Content Template (contemplate) module. It provides access to all of a content type's fields within the $content variable (which is delivered wholesale to the node-nodetype.tpl.php. The contemplate is php, so you can add logic and conditional formatting for the node-reference fields (usually clearly labeled in the contemplate).
And don't overlook the simple solution of the content type's 'display fields' tab (next to manage fields tab), where you can control some field outputs right out of the gate.

Categories