V
V
Vlad1712015-09-21 04:37:38
Drupal
Vlad171, 2015-09-21 04:37:38

How to display different types of materials in different regions on one page?

I'm learning Drupal. In order to delve deeper into the operation of the system, I decided to start by creating my own theme from scratch. I created page.tpl, created my own types of materials and redefined output templates for them (node--type.tpl). The problem is that the added content of different types is always displayed in the same region. The default is "content". Yes, you can assign a different region to the content and the content is simply displayed in a different location. I tried to assign the material to the block through the "Show block for certain types of materials", but then the teaser is still displayed in the "content", when you click on the link to the full description, the material appears in the desired block, but is duplicated in the "content"
Question: how to make one type of added material displayed only in one specific region, the other - in another on the same page. I know about Views, I didn’t really understand it, but I want to implement it at the code level and not with the help of auxiliary modules. There is a $content variable through which the content is displayed, perhaps there is a way to display the content of a particular type of material through it. Anyone help?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
afi13, 2015-09-21
@Vlad171

Views is no longer an auxiliary module, but a must have. In Drupal 8, it is already included in the core. And using Views would be the right thing to do in this situation.
If you still want to use a custom block, then you need to use hook_block_info()to declare blocks. One block for each type of material, or make a settings form for the block using the hook hook_block_configure(), where you can choose which type of material to display in this block. Next, hook_block_view()you need to select the node of the desired type from the database, you can use something like this:

$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node');
$query->propertyCondition('status', NODE_PUBLISHED);
$query->propertyCondition('type', 'CONTENT_TYPE');
$result = $query->execute();
$nodes = node_load_multiple(array_keys($result['node']));
where in CONTENT_TYPE substitute the machine name of the material type you need. And now you can use node_view_multiple()it to display all the received nodes in the desired display mode.

H
heartdevil, 2015-09-21
@heartdevil

Hello.
According to the logic that drupal suggests, the most correct way is to create a custom block for each type of material and assign a region to this block. This is how you can create a custom blocktyts .
To change the standard output of content in drupal, all sorts of preprocess hooks are usually used. For example, this hook
function THEME_preprocess_page(&$vars, $hook)

T
Tlito, 2015-09-21
@tlito

you need to master Display Suite tlito.ru/node/126

A
Alexander Malkov, 2015-10-02
@mav5555

And, as an option, there are good lessons with examples webcraftsmen.ru/content/drupal-7-polzovatelyu-vved...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question