Core/getElementsByTemplateId

From PunchCMS
Revision as of 22:14, 25 December 2008 by Admin (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

PCMS_Client->getElementsByTemplateId(templateId, [getFirst], [recursive], [random])

Overview

Get a collection of elements with a specific template id from the root folder of the CMS.

Arguments

templateId [integer]
Template id of the elements you are looking for.

getFirst [boolean, optional]
Indicate if you want to get only the first found Element or a collection of Elements. Default is FALSE.
This is deprecated. You should use the getElementByTemplateId() method instead.

recursive [boolean, optional]
Indicate if you want to search trough the tree or only on the first level. Setting this to TRUE can be very time consuming. Default is FALSE.

random [boolean, optional]
Indicate if you want to randomize the returned collection. Default is FALSE.

Returns

If Elements are found matching the criteria this method returns a valid Elements object. Otherwise an empty collection. That way you can test if you get a valid return using the count() method.

If the getFirst argument was set to TRUE and an Element was found it will return a valid Element object. Otherwise NULL.

Example

$objCms = PCMS_Client::getInstance();
 
// Get a collection of Elements with template API name 'Item'.
$objElements = $objCms->getElementsByTemplateId(3456);
foreach ($objElements as $objElement) {
    // Loop through the collection.
}