Fatal error: Uncaught Error: Call to a member function get() on null in /core/cache/includes/elements/modsnippet/186.include.cache.php:21 Stack trace: #0 /core/model/modx/modscript.class.php(70): include() #1 /core/model/modx/modparser.class.php(536): modScript->process(NULL) #2 /core/components/pdotools/model/pdotools/pdoparser.class.php(273): modParser->processTag(Array, true) #3 /core/model/modx/modparser.class.php(250): pdoParser->processTag(Array, true) #4 /core/components/pdotools/model/pdotools/pdoparser.class.php(65): modParser->processElementTags('', '<!doctype html>...', true, false, '[[', ']]', Array, 9) #5 /core/model/modx/modresponse.class.php(69): pdoParser->processElementTags('', '<!doctype html>...', true, false, '[[', ']]', Array, 10) #6 /core/model/modx/modrequ in /core/cache/includes/elements/modsnippet/186.include.cache.php on line 21
<?php /* $tv = Name der Template Variablen $id = ID der Ressource Beispiel: [[!myFF? &tv=`pagetitle` &id=`27`]] */ //------------ Template Variable einer bestimmten Ressource-ID ausgeben ---------------------// $parent = $modx->getObject('modResource', $id); //Der Aufruf zwischen den RessourceFields und den vom User angelegten TV's unterscheidet sich durch "get" und "getTVValue", deswegen if else...// if ($tv == "pagetitle" or $tv == "longtitle" or $tv == "description" or $tv == "alias" or $tv == "link_attributes" or $tv == "published" or $tv == "pub_date" or $tv == "unpub_date" or $tv == "parent" or $tv == "isfolder" or $tv == "introtext" or $tv == "content" or $tv == "richtext" or $tv == "template" or $tv == "menuindex" or $tv == "searchable" or $tv == "cacheable" or $tv == "createdby" or $tv == "createdon" or $tv == "editedby" or $tv == "editedon" or $tv == "deleted" or $tv == "deletedon" or $tv == "deletedby" or $tv == "publishedon" or $tv == "publishedby" or $tv == "menutitle" or $tv == "donthit" or $tv == "privateweb" or $tv == "privatemgr" or $tv == "content_dispo" or $tv == "hidemenu" or $tv == "class_key" or $tv == "context_key" or $tv == "content_type" or $tv == "uri" or $tv == "uri_override" or $tv == "hide_children_in_tree" or $tv == "show_in_tree" or $tv == "properties") {return $parent->get($tv);} else if ($tv == null) {return "Keine Werte gefunden!";} else { if ($parent->getTVValue($tv) != null) {return $parent->getTVValue($tv);} else {return "TV nicht gefunden oder enthält keine Werte!";} }
This question has been answered by BobRay. See the first response.
if ($parent) { /* Your code here */ } else { /* Resource is at root of tree -- do something else or do nothing*/ }