runSnippet API MODX Evo ✈ Evolution CMS
- Разработчикам
- API
- runSnippet
Поддержать: USDT TRC20: TBGKTYDs4yzU17vQbobbUB8epFFtFb6PKh
Menu
- addEventListener
- changeWebUserPassword
- clearCache
- getActiveChildren
- getAllChildren
- getCachePath
- getChildIds
- getChunk
- getConfig
- getDocument
- getDocumentChildren
- getDocumentChildrenTVarOutput
- getDocumentChildrenTVars
- getDocumentObject
- getDocuments
- getFullTableName
- getKeywords
- getLoginUserID
- getLoginUserName
- getLoginUserType
- getManagerPath
- getMETATags
- getPageInfo
- getParent
- getParentIds
- getPlaceholder
- getSnippetId
- getSnippetName
- getTemplateVar
- getTemplateVarOutput
- getTemplateVars
- getUserData
- getUserDocGroups
- getUserInfo
- getVersionData
- getWebUserInfo
- hasPermission
- insideManager
- invokeEvent
- isBackend
- isFrontend
- isMemberOfWebGroup
- logEvent
- makeList
- makeUrl
- mapPath
- parseChunk
- parseText
- parseProperties
- putChunk
- regClientCSS
- regClientHTMLBlock
- regClientScript
- regClientStartupHTMLBlock
- regClientStartupScript
- removeAllEventListener
- removeEventListener
- runSnippet
- sendAlert
- setPlaceholder
- stripTags
- toPlaceholder
- toPlaceholders
- userLoggedIn
- webAlert
- sendmail
8665
runSnippet API MODX Evo ✈ Evolution CMS
Возвращает результат выполнения сниппета с заданными параметрами
string runSnippet(string $snippetName [, array $params]);
$snippetName - название сниппета (чувствительно к регистру!)
$params - массив со значениями параметров
Пример
$txt = $modx->runSnippet( 'Ditto', array( 'startID' => 2, 'summarize' => 2, 'removeChunk' => 'Comments', 'tpl' => 'ditto_blog', 'paginate' => 1, 'extenders' => 'summary,dateFilter', 'paginateAlwaysShowLinks' => 1, 'tagData' => 'documentTags' ) ); //вернет результат работы сниппета Ditto, который идентичен вызову: [[Ditto? &startID=`2` &summarize=`2` &removeChunk=`Comments` &tpl=`ditto_blog` &paginate=`1` &extenders=`summary,dateFilter` &paginateAlwaysShowLinks=`1` &tagData=`documentTags`]]
Источник Функции
Файл: manager/includes/document.parser.class.inc.php
Строка: 1689
function runSnippet($snippetName, $params= array ()) {
if (isset ($this->snippetCache[$snippetName])) {
$snippet= $this->snippetCache[$snippetName];
$properties= $this->snippetCache[$snippetName . "Props"];
} else { // not in cache so let's check the db
$sql= "SELECT * FROM " . $this->getFullTableName("site_snippets") . " WHERE " . $this->getFullTableName("site_snippets") . ".name='" . mysql_escape_string($snippetName) . "';";
$result= $this->dbQuery($sql);
if ($this->recordCount($result) == 1) {
$row= $this->fetchRow($result);
$snippet= $this->snippetCache[$row['name']]= $row['snippet'];
$properties= $this->snippetCache[$row['name'] . "Props"]= $row['properties'];
} else {
$snippet= $this->snippetCache[$snippetName]= "return false;";
$properties= '';
}
}
// load default params/properties
$parameters= $this->parseProperties($properties);
$parameters= array_merge($parameters, $params);
// run snippet
return $this->evalSnippet($snippet, $parameters);
}
Примечания
Массив параметров, получаемых этой функции должны быть в форме 'В параметре' => 'значение'; Если вы предпочитаете вызов более читаемый функцию, создать массив первых, таких как:
$params['param1'] = 'value1';
$params['param2'] = 'value2';
$html = $modx->runSnippet('mysnippet', $params);