كيف يمكنني إضافة بعض التعليمات البرمجية ل html بعد عنصر في الصفحة الرئيسية ؟

magento.stackexchange https://magento.stackexchange.com//questions/78179

  •  13-12-2019
  •  | 
  •  

سؤال

ما أريد تحقيقه هو أن لدي بعض الكود في cms/الصفحة الرئيسية/التصميم الذي كنت ترغب في إدراج بعد عنصر معين في الصفحة الرئيسية.هذا هو 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>

و محتوى النص.phtml يجب أن يكون الكود من علامة التبويب "تصميم".حسنا أنا لا أريد أن إزالته من تصميم ووضع كل من التعليمات البرمجية html.هل هناك دالة أو طريقة للاتصال محتوى التصميم من الصفحة الرئيسية ؟ هذا هو محتوى القالب/الصفحة الرئيسية/النص.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