Cristi
Cristi

Reputation: 61

What does it mean PHP code? Magento

I have a site with a Magento theme and i found this code PHP.

<div class="product-options sss" id="product-options-wrapper">
    <?php echo $this->getChildHtml('', true, true);?>                    
    <?php if ($this->hasRequiredOptions()):?>
        <p class="required"><?php echo $this->__('* Required Fields') ?></p>
    <?php endif;?>
</div>

Who is this in this code? My div?

getChildHtml('', true, true);

From what I found on the internet I realized that '' means all the kids a div (whose div?)

I do not understand what parameters are used boolean true true ... in helping them?

I found it on the internet getChildHtml method takes things from an XML file.Where can I find this file?

Can you give me explain with a simple example code please?

Thanks in advance!

Upvotes: 0

Views: 122

Answers (2)

Deepak Mankotia
Deepak Mankotia

Reputation: 4564

$this in above code refers to current class(object).

'getChildHtml' method renders a child block according to the block name or alias supplied in the argument.

<?php echo $this->getChildHtml('',true,true) ?>
  • The first argument is the name or alias of a child block. If supplied, it returns the output of that child block. If this argument is not supplied or passed as a blank string, it renders all the child blocks specified in the layout.
  • The second argument $useCache is a Boolean which is by default true. If it is true, the block is cached if the block cache is enabled under the Caching settings in the admin panel. If it is false, the block is not cached even if block cache is enabled.
  • The third argument $sorted is also a Boolean which is by default false. If it is true, the child blocks are rendered according to the sorting order defined by before and after attributes.

Example :

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

In above example is added to the Magento layout XML in app/design/frontend/base/default/layout/page.xml

This is how we create block in XML file :

<block type="core/text_list" name="content" as="content" translate="label">
    <label>Main Content Area</label>
</block>

Upvotes: 3

Samvel Avanesov
Samvel Avanesov

Reputation: 422

The surrounding HTML code is client side. Your inner PHP code is server-side. The $this refers to the current executing class function, in this case - Magento template controller.

You can check out an example of developing with Magento templates here: http://code.tutsplus.com/articles/magento-theme-development-template-files--cms-21040

Upvotes: 1

Related Questions