weboftalent / portlets
Module to quickly render portlets of data from a simple template call
Installs: 262
Dependents: 3
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 1
Open Issues: 2
Type:silverstripe-vendormodule
Requires
- php: ~5.6|~7.0
- silverstripe/framework: ^4.1
Requires (Dev)
- phpunit/phpunit: ^5.7
- squizlabs/php_codesniffer: ^2.3
This package is auto-updated.
Last update: 2024-10-27 08:19:52 UTC
README
- Adds a convenience template call that allows one to search for N of a certain type of DataObject and then render them with a given template.
- Forces interfaced access to information about the data object such as title and image.
Installation
composer require "weboftalent/portlets:^4"
Usage
Interface for Models
For a model to be rendered as a portlet, it must provide the 3 following methods and implement the RenderableAsPortlet interface
public function getPortletTitle();
public function getPortletImage();
public function getPortletCaption();
Templates
The model being rendered must implement the RenderableAsPortlet interface mentioned previously. An example call to render portlets is as follows:
$RenderPortlet('Activity','','Title',2,'SmallTitleAndImage')
The parameters are as follows:
- The class name, in this case we are looking objects of class Activity
- Filter, i.e. the WHERE clause of the search. In this case no filter has been applied
- The sort field, in this case title.
- The number of items to return, in this case 2
- The name of the template used to render the portlets, here SmallTitleAndImage
In the template used to render the portlet, the records can be accessed using <control Records> - an example is below.
<ul class="slides">
<% control Records %>
<li>
<a href="$Link"><h5>$PortletTitle</h5>
<% control PortletImage %><% control SetWidth(170) %><img src="$URL"/><% end_control %><% end_control %>
</a>
<% end_control %>
</li>
</ul>
Silverstripe Version Compatibility
2.4 (tested with 2.4.5+) - stable24 branch 3.0 - stable30 branch