2011-03-04 4 views
0

나는 Drupal 7 웹 사이트에서 일하고 있습니다. 일부 페이지에는 맞춤 레이아웃이 필요합니다. 그래서 page - customContentTypeName.tpl.php 파일을 만들었고 완벽하게 해결되었습니다.Drupal 7 : 페이지에 사용자 정의 컨텐츠 유형 필드 호출하기

문제는 페이지 tpl에 일부 필드를 표시해야한다는 것입니다. 아래 코드는 노드 tpl에서 제대로 작동하지만 페이지 tpl은 다음과 같습니다./

<?php print $content['field_images']['#items']['0']['filename']; ?>" /> 

어떻게 사용자 정의 필드를 페이지 tpl로 호출 할 수 있습니까?

감사합니다! 고마워요 !! **


사용자 정의 필드 편집에 **

정렬 ... 여기에 튜토리얼 비디오입니다 : http://lin-clark.com/blog/intro-drupal-7-theming-fields-and-nodes-templates#comment-54

답변

2

7에서 변경된 구조 필드는 모국어에 의해 키가 있습니다 (기본적으로 "정의되지 않음"을 의미하는 "und") 다음 예제를 따라갈 수 있습니다.

// Array of Image values 
$images = $node->field_images['und']; 

//If you don't know the language, the value is stored in: 
$node->language 


// First image 
$image = $images[0]; 



// If you need informations about the file itself (e.g. image resolution): 
image_get_info($image["filename"]); 


// If you want to access the image, use the URI instead of the filename ! 
$public_filename = file_create_url($image["uri"]); 


// Either output the IMG tag directly, 
$html = '<img src="'.$public_filename.'"/>'; 

// either use the built-in theme function. 
$html = theme(
    "image", 
    array(
     "path" => $public_filename, 
     "title" => $image["title"] 
    ) 
); 

참고로 (CDN 서비스와의 통합을 쉽게하기 위해) 페이지에 이미지를 포함하기 위해 filename 대신을 사용하십시오. page.tpl.php 를 들어

+0

티저 모드 (예 : 많은 노드를 나열하는 분류학 용어 페이지)에서 이러한 필드는 기본적으로 변수 $ 노드에 제공되지 않습니다. – wildpeaks

+0

덧붙여서, StackOverflow의 드루팔 (Drupal) 전문 분야는 며칠 만에 공개 베타 버전으로 열립니다 : http://drupal.stackexchange.com – wildpeaks

2

직접 당신이 변수 $ 노드

$node['field_images']['und'][0]['filename'] 

다른 사용 $ 페이지 변수를 사용할 수있는 노드에 액세스합니다.

$page['content']['system_main']['nodes'][1]['field_images']['#items'][0]['filename']; 

그러나 페이지 변수에는 노드가 두 개 이상있을 수 있습니다.

0

테마 개발자를위한 drupal에는 유용한 두 개의 모듈이 있습니다. Devel 및 Theme_developer Devel 모듈은 dsm()이라는 기능을 제공합니다. dsm을 사용하면 요소가 다른 오브젝트에 저장되는 방법을 인식 할 수 있습니다. 예를 들어, dsm ($ node) 페이지의 노드 구조가 메시지 상자에 표시됩니다. 코드에 명령문을 입력 할 수 있습니다.