Know what $this-> points to

PHP uses a special variable, $this->, which always points to the “current object”. But what is the “current object”? In Frog, the meaning of $this-> changes depending on where you use it. Here is it how works:

  • in the Layout, $this-> points at currently displaying page, whatever it is.
  • in the Body of page, $this-> points at that page only.
  • in a Page-part, $this-> points at the page to which that part belongs — even if it is “inherited” by child pages with the “true” condition as in:
    <?php $this->content('sidebar', true); ?>
    [For example, if “sidebar” of “Homepage” uses $this->, and that sidebar is inherited by child pages, then $this-> still refers to the homepage!]
  • in a Snippet, $this-> will behave as outlined above, depending on whether you call the snippet in your layout, in the body of a page, or in a page-part.

Or, in summary form:

Layout $this-> = currently displaying page
Body = that specific page
Page-part = always owning page
Snippet as above, depending on where it is called
     

Frog CMS Demo

Public front end website click here
Administration backend click here

Opensource.com admin login info:
login: admin
password: demo123

Help us!

If you use and like Frog CMS, then please consider making a donation.


Click here to lend your support to: Frog CMS and make a donation at www.pledgie.com !