Difference between revisions of "Core/getElementByTemplate"
(New page: __NOTOC__ ==== PCMS_Client->getElementByTemplate(templateApiName, [recursive], [random]) ==== === Overview === Get the first element with a specific template API name from the root folder ...) |
(→Returns) |
||
Line 13: | Line 13: | ||
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'''. | 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 === | === Returns === | ||
− | If an element is found matching the criteria this method returns a valid Element object. Otherwise NULL. | + | 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 [http://www.php.net/manual/en/function.is-object.php is_object()] method. |
− | That way you can test if you get a valid return using the [http://www.php.net/manual/en/function.is-object.php is_object()] method. | + | |
=== Example === | === Example === | ||
<source lang="php"> | <source lang="php"> |
Latest revision as of 17:19, 25 December 2008
PCMS_Client->getElementByTemplate(templateApiName, [recursive], [random])
Overview
Get the first element with a specific template API name from the root folder of the CMS. It is possible to search recursivly through the element tree.
Arguments
templateApiName [string]
Template API name 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->getElementByTemplate("Pages"); if (is_object($objElement)) { // Found Element with Template API name. }