လက်ရှိတည်နေရာ: ပင်မစာမျက်နှာ> နောက်ဆုံးရဆောင်းပါးများစာရင်း> Magento စိတ်ကြိုက် layout နှင့် template ကိုဒီဇိုင်းလက်တွေ့လမ်းညွှန်

Magento စိတ်ကြိုက် layout နှင့် template ကိုဒီဇိုင်းလက်တွေ့လမ်းညွှန်

gitbox 2025-06-15

1 ။ နိဒါန်း

Magento သည်အထူးသဖြင့်အပြင်အဆင်နှင့်တင်းပလိတ်ဒီဇိုင်းတွင်အားကောင်းသောစိတ်ကြိုက်စွမ်းဆောင်ရည်စွမ်းရည်ရှိသောလူကြိုက်များသောအရင်းအမြစ် e-commerce e-commerate platform ဖြစ်သည်။ ဤဆောင်းပါးသည် Magento မှတစ်ဆင့် Magento မှတစ်ဆင့် Magento မှတဆင့်စိတ်ကြိုက်အပြင်အဆင်နှင့်ပုံစံဒီဇိုင်းကိုမည်သို့အကောင်အထည်ဖော်ရမည်ကိုအသေးစိတ်ဖော်ပြထားသည်။

2 ။ layout ကိုစိတ်တိုင်းကျ

2.1 စိတ်ကြိုက်အပြင်အဆင်ဖိုင်တစ်ခုကိုဖန်တီးပါ

Magento တွင် layout ကိုစိတ်ကြိုက်ပြင်ဆင်ခြင်းတွင်ပထမခြေလှမ်းမှာ layout file တစ်ခုဖန်တီးရန်ဖြစ်သည်။ Magento သည်စာမျက်နှာတစ်ခုစီသို့ထူးခြားသောစာမျက်နှာလက်ကိုင်တစ်ခုအဖြစ်သတ်မှတ်ပြီးလက်ကိုင်ပေါ်တွင် အခြေခံ. ကွဲပြားခြားနားသော layout ဖွဲ့စည်းပုံကိုသတ်မှတ်နိုင်သည်။

 
<!-- Page layout files များကိုစိတ်ကြိုက်ပြုပြင်ပါ,အမည်မဲ့ my_layout.xml -->
<?xml version="1.0"?>
<layout version="1.0">
  <default>
    <reference name="head">
      <action method="addItem">
        <type>skin_css</type>
        <name>css/custom.css</name>
      </action>
    </reference>
  <block type="core/template" name="custom_block" template="custom/custom.phtml" />
</reference>

အထက်ပါကုဒ်သည် Custom CSS နှင့် template လုပ်ကွက်ပါသော My_layout.xml အမည်ရှိ layout file တစ်ခုဖြစ်ပါသည်။ စာမျက်နှာတစ်ခုစီသည် layout file တစ်ခုနှင့်ကိုက်ညီကြောင်း ကျေးဇူးပြု. မှတ်သားပါ။ ကွဲပြားခြားနားသောစာမျက်နှာများအတွက် layout ကိုဖွင့်ရန်လိုအပ်ပါကသင်အဆင်သင့်ဖိုင်များကိုဖန်တီးနိုင်သည်။

2.2 စိတ်ကြိုက် layout ကို Apply

အပြင်အဆင်ဖိုင်ကိုဖန်တီးပြီးနောက်သင်က controller ရှိ layout ကိုဖွင့်ပြီးအသုံးချရန်လိုအပ်သည်။

 
<?php
class Custom_Module_IndexController extends Mage_Core_Controller_Front_Action
{
  public function indexAction()
  {
    $this->loadLayout('my_layout');
    $this->renderLayout();
  }
}

အထက်ပါ Controller Code သည် Custom Layout File ကို loadlayout ('my_layout' မှတဆင့်ဖွင့်သည်။

3 ။ ထုံးစံပုံစံဒီဇိုင်း

3.1 စိတ်ကြိုက်ပုံစံများကိုဖန်တီးပါ

Magento Templates များသည် Phtml ဖိုင်များဖြစ်ပြီးစာမျက်နှာရှုခင်းများကိုအကောင်အထည်ဖော်ရန် HTML နှင့် PHP code များကိုပေါင်းစပ်ထားသည်။ ဤတွင်ရိုးရှင်းသောဓလေ့ထုံးစံပုံစံဥပမာတစ်ခုဖြစ်ပါသည်။

 
<!-- Custom Template Files,အမည်မဲ့ custom.phtml -->
<div>
  <h1>Custom Template</h1>
  <p>This is my custom template.</p>
  <?php echo $this->__('Some text.'); ?>
</div>

ဤ template file တွင် standard HTML element များနှင့် output များပါ 0 င်သည်

3.2 ရည်ညွှန်းထားသော template ဖိုင်များဖိုင်များ

template တစ်ခုကိုဖန်တီးပြီးနောက်သင်ဟာအဆင်အပြင်ဖိုင်ကို block တစ်ခုထည့်ပြီးအကြောင်းအရာကိုပြသရန် template file ကိုကိုးကားနိုင်သည်။

 
<!-- ပြန်လည်စစ်ဆေးကြည့်ရှု My_Extension ၏ local.xml စာချုပ်စာတမ်း -->
<?xml version="1.0"?>
<layout version="1.0">
  <default>
    <reference name="content">
      <block type="core/template" name="custom_block" template="custom/custom.phtml" />
    </reference>
  </default>
</layout>

အပေါ်က layout code သည် template ကိုအကောင်အထည်ဖော်ရန်နှင့်ပြန်ဆိုခြင်းများကိုအကောင်အထည်ဖော်ရန်ယခင်ကဖန်တီးထားသော template ကိုအသုံးပြုသော template area ရိယာကိုအသုံးပြုသည်။

အထက်ပါအဆင့်များမှတစ်ဆင့်သင်ကိုယ်တိုင်နှင့်အင်္ဂါရပ်များကြွယ်ဝသော e-commerce ဝက်ဘ်ဆိုက်ကိုတည်ဆောက်ရန် Magento ရှိစိတ်ကြိုက် layuuts နှင့် template files များကိုမည်သို့ဖန်တီးရမည်ကိုကျွမ်းကျင်စွာပြုလုပ်ခဲ့သည်။