Can someone pls guide me with this?
I have five images associated with a node which I have kept hidden. I want to show them in a block.
How do I show the images in the block belonging to the CURRENTLY DISPLAYED NODE?
So that as the node changes, it will automatically load the images of that node on the block?
I figured this has got to do with adding filters.
But I cant seem to get any
'current node' filter as such when I was seeing those lists.
I also read that I can pass an argument of the current node to the block. But In drupal 7, there is no such field called 'arguments' while editing the block....
Thanks
You can do that using views.
1- Create a new views block.
2- Under Fields section, choose your images field.
3- Under Contextual filters click Add then choose Content: Nid
4- Under When the filter value is NOT available choose Provide default value then Content ID from URL, then click Apply.
5- Save your view and go to the blocks manager page admin/structure/block and click configure beside your new views block.
6- Navigate to the bottom of the page to Content types, then check the content types you wanna have this block to be shown.
Hope this helps... Muhammad.
Related
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
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
A client wants a full page full of PDFs, and an option to be able to assign a PDF to a page automatically.
For example, conveyancing.pdf would appear on downloads.php (along with several others), but also have an option to tick 'yes I want this PDF to also feature on the conveyancing page'. Is this possible, and if so how would you approach it?
If I made a custom post type for the pdfs, is there an option to list all the pages it can appear on, like you'd tick categories but this would be 'pages'?
"a full page full of PDFs"?
Do you mean a page with links to multiple PDFs on the server?
Chrome / firefox and maybe IE have a built in PDF viewer and there is an option to save, download or print.
How to Upload & Link to a PDF file in WordPress
if i get you right, you want to upload pdf files from the admin panel and attach them to pages.
since you didn't specify what you already done, i will start from the beginning.
I've done this before on some project, i needed to let a client upload documents to post type page and custom post types. you can create a new custom fields on your code if you like too but i think if you'r out of time, you can installed for example the WCK plugin because besides of options like create new custom post types or taxonomy easily, it also let you create custom fields with repeater (which is not freely in every other good custom field creator plugin).
create with the plugin a new meta box and then the document field (you will need to do it for each post type). after that, you will see the new custom field on the post type you've been chosen, upload a document for the test and on you theme code call to get the field, check this link to get the detailed instructions.
after it will work for you you will want to add an option to attach some documents to other page by some checkbox right? you can create another custom field (checkbox) under the same meta box so it will Appear with every document field and then get the value on the code theme to check if it checked or not, that way you can control what documents will appear in the template you want to get by the checked checkbox of document ("show this document in other templates").
the problem with this should be how to get the id's of the pages who have the selected checkbox to the current page, i didn't try it but maybe you call all the pages with WP_Query and in the array use the specific post type you like and the custom field parameter to get only the pages with the check box, after that you can run a foreach on the array and use a condition to check for the value of each page checkbox, if it true get the custom field (document) and in the place to insert the post id use the id of the post in the foreach so it need to bring you the specific document. i would love to hear if it worked for you, good luck!
In the pages .tpl.php of my theme i can find several lines like
render($action_links)
displaying whole pages with a single command. Sometime i saw that the render argument is a block from my theme .info, but other times i see arguments i cannot identify that render default pages or elements of drupal.
How it works? And where i can find a list of default displayable pages?
In particular, i needed to display the content of the default drupal page "add content" in one of my pages, and i'm pretty sure i can do it using this render method, but i cannot find the correct argument.
EDIT: I found something like
drupal_render(node_add('NODE_TYPE'));
that seems to allow the display of a node add form, but what i need is the main add content page, containing the list of all the type of nodes that a user can add.
Are you new to Drupal? When I read your post, I'm almost sure that you have missed something with the Drupal's working. The variables you found in render() functions are "calculated" somewhere else in the code (in the modules part for the most).
You cannot find a list of constant variables to display them just like this.
I found this article about these mysterious variables that are rendered and I hope it will help: http://newsignature.com/articles/the-magic-behind-drupals-render-elements
If you just want to display the "add content" form somewhere on your site, just call its path (node/add).
EDIT AFTER CLARIFICATIONS:
First of all, you can set on which page you want the user lands after login. (I don't know why you're still talking about user profile template. Maybe I missed something again.)
But if I did understand what you're trying to achieve, I'll do that:
Create a menu (or simply use the "Navigation" menu that seems to be exactly what you need) with all the actions users can do. And I'll place this menu in the main content region. Do create a menu, go to Administration>Structure>Menus>Add menu. And add links like "node/add/article" or "node/add/news" or "node/add/page" or whatever your content-types are.
Place this menu in the region you want. If you want it to be like the main content of the page, place it in the main container. To do so, go to Administration>Structure>Blocks> Drag and drop your menu in the right region and Save.
Configure this block to appear only on the front page (the first page on user arrives after logged in) if you want so. To do so, in the Blocks administration page, click on "Configure" next to your block and check "show block on specific pages: Only the listed pages" and write down <front>
Create roles and permissions for your different sorts of users. That will automatically show them the links they are allowed to see. To set permissions, go to Administration>People>Permissions and check in the "Node" section which content-type each role can create.
I hope I didn't forget anything. Please tell me if it is clear enough.
I have a content type named announcements and I am displaying a view block of latest announcements in a content which is belongs to announcements content type. This block has three fields: Taxonomy term, Title and link. I have put following filters:
1.Content: Type (= Announcements)
2.Content: Published (Yes)
The block is working correctly, but it is displaying current node fields too.
How can I not display current node fields in my view block?
thanks!
To make your block aware of what node it's being displayed on and to filter out fields that match that current node, you have to set up a 'Contextual filter'.... That includes settings to make your block aware of the current node, logged in user, etc.
Add a Contextual filter (under the 'Advanced' section of the view)
Select Content: Nid as the field you want to set up a contextual filter for
Select 'Provide default value' = 'Content ID from URL'. This way the block will use as a filter the URL of the node it is appearing from when the filter is not found in the URL (and you won't really be using the URL to pass args, so it'll always default to this)
Now here's what's going to exclude those fields rather than display precisely them: in the collapsed 'More' section at the bottom of these settings is a checkbox 'Exclude'. Make sure you check that before saving the configurations.
That's it! Let us know if it works.