2014-06-23 2 views
1

magento에서 페이지 제목을 변경하고 싶습니다. 내가 대신 내 app/design/frontend/default/customPackage/template/page/html/head.phtml에서 는 라인magento에서 head.phtml을 다시 쓰는 방법

<title> 
<?php 
    if ($current_product = Mage::registry('current_product')) { 
     echo substr($current_product->getName() . " - " . Mage::helper('core')->currency($current_product->getFinalPrice(), true, false),0,69); 
    } else { 

     echo substr(str_replace("- Products","",$this->getTitle()),0,100); 
    } 
    ?></title> 

을 (난 그냥 카탈로그 페이지의 제목을 수정할 것) 모든 페이지 제목을 제어있다하지만 난 app/design/frontend/default/customPackage/template/page/html에 head.phtml에서 직접 수정하지 않습니다 이 app/design/frontend/default/customPackage/template/catalog/html/head.phtml 대신

답변

2

귀하의 질문에 대답 할 수 있도록, 내 자신의 모듈 tempate files.Let의 말에 다른 head.phtmlhead.phtml를 교체하려면, 기본적으로 우리는 page/html/head.phtml 파일이 정의 된 위치를 찾을 필요가있다. 답은 레이아웃 파일에 있습니다. 구체적으로는 page.xml입니다. 위치는 app/design/frontend/<your_package>/<your_theme>/layout/page.xml입니다. 해당 파일의 내부 핸들 <default>에서, 당신은

  • <default>이 레이아웃 핸들러로 알려져있다

    <default translate="label" module="page"> 
        <label>All Pages</label> 
        <block type="page/html" name="root" output="toHtml" template="page/3columns.phtml"> 
    
         <block type="page/html_head" name="head" as="head"> 
          <action method="addJs"><script>prototype/prototype.js</script></action> 
          <action method="addJs"><script>lib/ccard.js</script></action> 
          <action method="addJs"><script>prototype/validation.js</script></action> 
          <action method="addJs"><script>scriptaculous/builder.js</script></action> 
          ------- 
         </block> 
         --------- 
        </block> 
    </default> 
    

    을 볼 수 있습니다. 이 핸들러 아래에있는 블록은 모든 페이지에서 자홍색으로 표시됩니다.

  • 블록 page/html이 루트 블록입니다. 다른 모든 블록의 부모 블록입니다. 페이지 당 하나의 루트 블록 만 있어야합니다. 이 블록 내부의 내용을 변경하기 위해 사용자 정의 레이아웃 파일에서 이름이 root 인이 블록을 참조 할 수 있습니다.

  • 블록 page/html_head은 귀하의 질문에서 참조 된 블록입니다. 이 블록은 페이지의 <head /> 섹션을 보유하는 데 사용됩니다 (html 트리 관점). magento가 핵심 자바 스크립트와 CSS를이 블록 안에로드하는 것을 볼 수 있습니다.

page/html_head은 이미 본 템플릿과 함께 설정되지 않습니다. 그럼 어떻게 page/html/head.phtml 본적이 ??? 그것은 magento 어딘가에 설정해야합니다. 이 블록의 백엔드 쪽을 보자. 모든 블록 메서드가 정의되어있다. 파일 위치는 app/code/core/Mage/Page/Block/Html/Head.php입니다. 예, 우리는 그것을 발견했습니다.

class Mage_Page_Block_Html_Head extends Mage_Core_Block_Template 
{ 
/** 
* Initialize template 
* 
*/ 
protected function _construct() 
{ 
    $this->setTemplate('page/html/head.phtml'); 
} 
------ 
} 

그래서 젠토 _construct() 방법으로, 여기 page/html_head 블록 템플릿 세트. 그것은 이제 사용자 지정 서식 파일에 page/html_head 블록의 위치를 ​​설정합니다 템플릿 위치

protected function _construct() 
{ 
    $this->setTemplate('app/design/frontend/default/customPackage/template/catalog/html/head.phtml'); 
} 

로 변경합니다.

블록 파일을 변경하지 않으려면 자체 모듈을 사용하여이 블록 파일을 다시 쓸 수 있습니다. 당신의 config.xml 파일에서는이

<config> 
    <global> 
     <blocks> 
      <page> 
       <rewrite> 
        <html_head>Namespace_Modulename_Block_Html_Head</html_head> 
       </rewrite> 
      </page> 
     </blocks> 
    </global> 
</config> 

를 사용해야합니다 그리고 당신은 핵심 파일이 그대로있는이 방법 app/code/local/Namespace/Moduleame/Block/Html/Head.php

<?php 
class Namespace_Modulename_Block_Html_Head extends Mage_Page_Block_Html_Head 
{ 
    protected function _construct() 
    { 
     $this->setTemplate('app/design/frontend/default/customPackage/template/catalog/html/head.phtml'); 
    } 
} 

에 블록 파일을 정의해야 여전히 템플릿 경로를 변경할 수 있습니다.

+0

답변 하단의 ''메소드를 사용하는 것이 가장 좋은 해결책입니다. 감사! – Justin

관련 문제