Difference between revisions of "Core/getElementByTemplateId"

From PunchCMS
Jump to: navigation, search
(New page: __NOTOC__ ==== PCMS_Client->getElementByTemplateId(templateId, [recursive], [random]) ==== === Overview === Get the first element with a specific template id from the root folder of the CM...)
 
(No difference)

Latest revision as of 22:12, 25 December 2008

PCMS_Client->getElementByTemplateId(templateId, [recursive], [random])

Overview

Get the first element with a specific template id from the root folder of the CMS. It is possible to search recursivly through the element tree.

Arguments

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

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 collection the Element is picked from. If there are more than 1 Element based on the requested template the return object will vary each time this method is called. Default is FALSE.

Returns

If an element is found matching the criteria this method returns a valid Element object. Otherwise NULL. That way you can test if you get a valid return using the is_object() method.

Example

$objCms = PCMS_Client::getInstance();
 
$objElement = $objCms->getElementByTemplateId(345);
if (is_object($objElement)) {
    // Found Element with Template id 345.
}