bringyourownideas / inheritage-by-sitetree
Allows you to inheritage information from the parent pages
Fund package maintenance!
spekulatius
www.buymeacoffee.com/spekulatius
Installs: 7
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 2
Open Issues: 2
Type:silverstripe-module
Requires
- silverstripe/cms: ^3.0
- silverstripe/framework: ^3.0
Replaces
README
Allows you to inherit any property from parent pages (any level). Check out the usage example to see how it works.
Features
-
Loading information from direct or indirect parent page.
-
This is only tested for db-fields. Has_one or has_many hasn't be confirmed.*
Usage
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.
Requirements and installation
Requirements
- SilverStripe Framework and CMS ^3.0
Installation
-
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
misc: future ideas/development, issues, contrib, license
This project is supported by bring your own ideas Ltd.. Bring Your Own Ideas Ltd. helps you to make your project ideas to reality.