getProperties(), why would you need to use these in the build process? Example?
For the build process, I use only $snippets->setProperties($properties); Not getProperties().
I’m confused; getProperties is used internally; that is not really a function that needs to be called explicitly, ever.
But I would like to use $snippets->getProperties($properties); (or an equivalent) in the snippet code.
My initial idea, for the default configuration of the ajaxSearch snippet, was to use Default properties .
For this I have defined a property set inside a _build/data/properties/properties.ajaxSearch.php file like this:
<?php
/**
* @package ajaxSearch
* @subpackage build
*/
$properties = array(
array(
'name' => 'debug',
'desc' => 'Debug option.',
'type' => 'textfield',
'options' => '',
'value' => '0',
),
array(
'name' => 'grabMax',
'desc' => 'The maximum number of search results displayed.',
'type' => 'textfield',
'options' => '',
'value' => '6',
),
array(
'name' => 'tplResult',
'desc' => 'The template used to display a result.',
'type' => 'list',
'options' => '',
'value' => 'result',
),
... and so on for all the default properties for ajaxSearch
);
return $properties;
?>And these properties are loaded as default properties inside a transport.snippet.php file:
$properties = include $sources['data'].'properties/properties.ajaxSearch.php';
$snippets[1]->setProperties($properties);
So with a document with [!AjaxSearch!] as snippet call, I retrieve the default parameters in the $scriptProperties array.
Until here all is correct.
Now, I would like create an another (hidden) document to handle the ajax request with [!AjaxSearch!], when the ajax mode is used.
In this case, with [!AjaxSearch!], I retrieve in the $scriptProperties array the default parameters as on the main snippet call.
Now with
[!AjaxSearch? &debug=`1` &tplResult=`myTplResult`!]
as snippet call on the main document. I get in the $scriptProperties array, the properties and the changed properties: debug and tplResult
On the second document where the snippet call is still [!AjaxSearch!], I get ONLY the default properties.
So to retrieve the correct &debug and &tplResult properties, I need to pass these properties, thru the ajax request. For this I need to pass these two custom properties thru a javascript script like this:
<script type="text/javascript">
//<![CDATA[
asvar=new Array();asvar[0]='{"cfg":"&debug=`1` &tplResult=`myTplResult` "}';
//]]>
</script>
To do this, I need,in the main document, to differentiate the default properties of the snippet from the custom properties added by the developper.
By using:
$snippet = $modx->getObject('modSnippet',array('name'=>'Doodles'));
$properties = $snippet->getProperties();I could retrieve these default properties. And by doing an array_difference between $properties and $scriptProperties, I determine which properties, I should pass to javascript to set up the appropriate call to the second document which handle the ajax request.
In this case, I simply pass a json structure with all the custom parameters:
{"cfg":"&debug=`1` &tplResult=`myTplResult` "}
This is possible by using $snippet->getProperties().
But if this method is not public and not allowed externally, How could I retrieve these properties ?
If I can’t retrieve the default properties, I can’t do an array_difference with the $scriptProperties array and I don’t know which are the custom properties
Obviously, I could pass to javascript all the properties of the $scriptProperties array. But this increase unecessarily the weight of the first page.
So, this is not an issue, but a change request. Does it possible to have in the futur a public non-internal method to retrieve the default properties linked to a snippet, like the $snippet->getProperties() method ?