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

4.0.3 2018-05-01 02:52 UTC

This package is auto-updated.

Last update: 2024-11-27 08:34:46 UTC


README

Build Status Scrutinizer Code Quality Code Coverage Build Status codecov.io

Latest Stable Version Latest Unstable Version Total Downloads License Monthly Downloads Daily Downloads

Dependency Status Reference Status

codecov.io

  • 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