문제

내가 달성하고 싶은 것은 cms/homepage/design에 HTML 코드가 있다는 것입니다. 이 코드는 홈페이지의 특정 요소 뒤에 삽입하고 싶습니다.이것은 XML 코드입니다:

<cms_index_index translate="label">
        <reference name="content">
            <block type="sama_productblocks/list" name="sama_productblocks_newproducts" after="call_to_actions" template="sama_productblocks/list.phtml">
                <action method="setIdentifier"><id>homepage-latest</id></action>
            </block>

            <block type="core/template" name="top_banners" before="-" template="homepage/topbanners.phtml">
                <block type="experius_linkmanager/link_list" name="homepage_banner">
                    <action method="setIdentifier"><key>hoesjesoutlet-homepage_banner</key></action>
                </block>
                <block type="experius_linkmanager/link_list" name="homepage_small">
                    <action method="setIdentifier"><key>hoesjesoutlet-homepage_small</key></action>
                </block>
            </block>
            <block type="core/template" name="cta_banners" after="modelfilter_search" template="homepage/cta.phtml">
                <block type="experius_linkmanager/link_list" name="homepage_cta">
                    <action method="setIdentifier"><key>hoesjesoutlet-homepage_cta</key></action>
                </block>
            </block>
            <block type="core/template" name="home_text" after="modelfilter_search" template="homepage/text.phtml">
                <!-- Here should I call the html code -->
            </block>
        </reference>
    </cms_index_index>

text.phtml의 내용은 디자인 탭의 HTML 코드여야 합니다.글쎄, 나는 그것을 디자인에서 제거하고 모든 HTML 코드를 넣고 싶지 않습니다.홈페이지에서 디자인 내용을 불러오는 기능이나 방법이 있나요?이것은 template/homepage/text.phtml의 내용입니다.

<div class="cta_row">
    <?php // echo $this->getChildHtml('homepage_text');
    // here i want to put the html code from the design tab from homepage
    ?>
</div>
도움이 되었습니까?

해결책

HTML 콘텐츠를 새 phtml 파일에 넣으세요.이렇게 해야 합니다.

파일: app\design\frontend\{your_package}\{your_theme}\template\homepage\my_homepage.phtml

<!-- put your html code inside this file -->

즉, HTML 코드가 내부에 들어옵니다. my_homepage.phtml 주형.이제 XML 코드의 마지막 부분을 이와 같이 업데이트하세요.

<block type="core/template" name="home_text" after="modelfilter_search" template="homepage/text.phtml">
    <!-- call to your custom html code block -->
    <block type="core/template" name="my.homepage.block" as="homepage_text" template="homepage/my_homepage.phtml" />
</block>

이제 귀하의 text.phtml 이 통화를 보류합니다..

<?php echo $this->getChildHtml('homepage_text') ?>

그런 다음 모든 캐시를 지우고 페이지를 다시 로드하세요.이제 끝났습니다.

편집하다

해당 html 코드를 관리자가 편집할 수 있게 하려면 댓글에 언급한 대로 해당 html 코드를 식별자가 있는 정적 블록 안에 넣으세요. homepage_custom_code (여기서 무엇이든 사용할 수 있습니다) 그런 다음 XML 코드를 다음과 같이 변경하십시오.

레이아웃 업데이트 접근 방식

<block type="core/template" name="home_text" after="modelfilter_search" template="homepage/text.phtml">
    <!-- call to your custom html code block -->
    <block type="cms/block" name="my.homepage.sb" as="homepage_text">
         <action method="setBlockId">
               <block_id>homepage_custom_code</block_id>
         </action>
</block>

그런 다음 사용자 정의 블록을 호출하십시오. text.phtml 위에서 했던 것과 같은 방법입니다 ^^^^.

하드 코딩 접근 방식 :(나는이 싫어.)

그렇지 않으면 정적 블록을 직접 호출하십시오. text.phtml 이와 같이.

 <?php 
     $this->getLayout()->createBlock(
         'cms/block', 
         'my_custom_text_from_sb', 
          array('block_id' => 'homepage_custom_code')
      )
      ->toHtml() 
  ?>

양방향으로 작동합니다.그러나 나는 첫 번째 접근 방식을 권장합니다.나에게는 그것이 더 명확해 보인다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top