Allows you to inherit any property from parent pages (any level). Check out the usage example to see how it works.
-
Loading information from direct or indirect parent page.
-
This is only tested for db-fields. Has_one or has_many hasn't be confirmed.*
The following example shows a possible use case of two page types which have a fixed position in the information architecture and using inheritage to get the "color" field to the sublanding page.
<?php
/**
* In the SiteTree this page will be directly under the homepage.
*
* URL structure /landing
*/
class LandingPage extends Page
{
/**
* @var array
*/
$db = [
'Color' => 'Varchar',
];
}
class LandingPage_Controller extends Page_Controller
{
/* ... */
}
<?php
/**
* In the SiteTree this page will be directly under the landing page.
*
* URL structure /landing/sublanding
*/
class SubLandingPage extends Page
{
/* ... */
}
class SubLandingPage_Controller extends Page_Controller
{
/* ... */
}
in SubLandingPage.ss you can do this now:
<div>
<% cached 'color', $Top.ID, $Top.LastEdited %>
$GetFromParentPage(Color)
<% end_cached %>
</div>
to retrieve the Color value set on the parent. Please ensure you apply suitable caching to any calls.
- SilverStripe Framework and CMS ^3.0
-
Run the following command to install the package:
# install the package composer require bringyourownideas/inheritage-by-sitetree; git add composer.json composer.lock; git commit -m 'MINOR: adding inheritage-by-sitetree';
-
Set up your Extension
This can be done either via a yml configuration file (e.g. mysite/_config/config.yml):
Page: extensions: InheritageBySiteTreeExtension
or by checking the InheritageBySiteTreeExtension.php and adding the "non-extension" version of the module to your Page.php-file. The second option is more performant.
-
Run dev/build to load extension
# run dev/build to load extension php ./framework/cli-script.php dev/build
This project is supported by bring your own ideas Ltd.. Bring Your Own Ideas Ltd. helps you to make your project ideas to reality.