문제

I'm new to Drupal and I'm creating an event management website with it. I'm using Drupal 7 and I have created a custom content type called "event" and I have written my own theme. I have a problem with theming the custom content type. I have built a template file called node--event.tpl.php inside my theme folder so that it is used to display every event in the website. My problem is that I don't know how to use individual fields and put them in the places I want. For example my event content type has an overview (text), image, date, and venue (getlocation field) and I want to use them individually in my template file so that I can put each one inside an HTML tag individually and not as a whole. I have searched Google but found nothing. I have used modules like Panel and Display Suite but I can't make what I want with them. Any solutions or hints would be appreciated a lot.

Regards, Shakib

도움이 되었습니까?

해결책

The following document will show you how to get access to the fields:

https://api.drupal.org/api/drupal/modules!node!node.tpl.php/7

All this information is stored in the $node array. You can print the array to see it with print_r wrapped in html pre tags.

Example for a field named authors:

<?php $node->field_authors[0]['value'] ?> 

Or

<?php $node->field_authors[0]['safe'] ?> 

for a sanitized version.

Instead of printing the array with print_r you can use the Devel module

다른 팁

Install and enable Development module and then you can use function dpm(). This function prints a variable to the 'message' area of the page. Try it:

<?php dpm($content); ?> 

Your field has to be placed here:

<?php dpm($content['field_authors']); ?>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top