Usage
The package contains two snippets and two formit hooks, that use the following parameters1
RememberThisAdd
This snippet will display an add button. It has the following properties:
| Property | Description | Default |
|---|---|---|
| addId | This value (and the corresponding item title) is added to the list.2 | Current resource id |
| addTpl | Template for the add link. | (system setting) |
| tplPath | Base path for template chunks using @FILE binding. | (system setting) |
The Add template can contain a link or a form to add xPDO objects as an element
to the list. The form can contain form fields and the link can contain
parameters to set properties of the remembered element. The field names and url
parameters must be prefixed with [[+rememberqueryadd]]property_.
With AJAX, the URL parameters of a link are not sent. The link also needs data attributes with the same names:
<a class="rememberadd" data-add="[[+rememberid]]"
data-[[+rememberqueryadd]]property_test="1"
href="[[+rememberurl]]&[[+rememberqueryadd]]property_test=1">Remember</a>
Placeholders
The following placeholders are available in the addTpl template chunk:
| Placeholder | Description |
|---|---|
| rememberurl | Link to add an xPDO object as element to the list. |
| rememberid | The identifier to reference the added element. |
| rememberqueryadd | The query parameter to add an element to the list3. |
RememberThisList
This snippet will display the remembered list. It has the following properties:
| Property | Description | Default |
|---|---|---|
| jsonList | Output a JSON-encoded array of element identifiers4. Elements with properties contain identifier and itemproperties. | 0 (No) |
| noResultsTpl | Template that is displayed, if the list is empty. | (system setting) |
| outerTpl | Outer template for the output of the list, if the list is not empty. | (system setting) |
| rowTpl | Row template for the output of a list element. | (system setting) |
| tplPath | Base path for template chunks using @FILE binding. | (system setting) |
| wrapperTpl | Wrapper template for the outer output or the empty output. | (system setting) |
The snippet tries to display a list from the database if the query parameter rememberthis is not empty.
Placeholders
The following placeholders are available in the rowTpl template chunk:
| Placeholder | Description |
|---|---|
| identifier | The identifier of the added element. |
| properties | The properties for the added element. |
| itemtitle | The title of the added element. This title is rendered with the chunk referenced by the itemTitleTpl system setting5 |
| deleteurl | The url to delete this element from the list. |
| deleteid | The row ID to delete this element from the list. |
| rowid | The row ID of the element. |
| iteration | The position of the element in the output, starting with 0. |
The following placeholders are available in the outerTpl template chunk:
| Placeholder | Description |
|---|---|
| count | The count of added elements in the list. |
| wrapper | The wrapper containing all rows of the list. |
The following placeholders are available in the wrapperTpl template chunk:
| Placeholder | Description |
|---|---|
| count | The count of added elements in the list. |
| wrapper | The output of the outerTpl or the noResultsTpl template chunk. |
RememberThisHook (FormIt hook)
The FormIt hook sets some placeholders in FormIt. You have to call the hook like this:
[[!FormIt?
&hooks=`...,RememberThisHook,...`
&rememberOuterTpl=`tplRememberOuterMail`
&rememberRowTpl=`tplRememberRowMail`
]]
The hook has the following properties:
| Property | Description | Default |
|---|---|---|
| rememberClearList | Clear the list after running the hook. | 0 (No) |
| rememberJsonList | Output a JSON-encoded array of element identifiers4. Elements with properties contain identifier and itemproperties. | 0 (No) |
| rememberNoResultsTpl | Template that is displayed, if the list is empty. | (system setting) |
| rememberOuterTpl | Outer template for the output of the list, if the list is not empty. | (system setting) |
| rememberRowTpl | Row template for the output of a list element. | (system setting) |
| rememberSaveList | Save the remembered list with a hash in the database and fill a placeholder with this hash. These lists don't expire. | 0 (No) |
| rememberTplPath | Base path for template chunks using @FILE binding. | (system setting) |
| rememberWrapperTpl | Wrapper template for the outer output or the empty output. | (system setting) |
Placeholders
The following placeholders are available in the rowTpl template chunk:
| Placeholder | Description |
|---|---|
| identifier | The identifier4 of the added element. |
| properties | The properties for the element. |
| itemtitle | The title of the added element. This title is rendered with the chunk referenced by the itemTitleTpl system setting5 |
| itemcount | The value of an input field with the name count_[[+rowid]], if the form is posted. |
| rowid | The row ID of the element. |
FormIt Placeholders
The following FormIt placeholders ([[!+fi. ...]]) are set by the hook:
| Placeholder | Description |
|---|---|
| rememberthis | The output of the rememberWrapperTpl template chunk (or the JSON encoded list of element identifiers4 and itemproperties, if the rememberJsonList property is enabled). |
| rememberthis.list | An array of element identifiers. Elements with properties contain identifier and itemproperties. |
| rememberthis.count | The count of added elements in the list |
| rememberthis.hash | The hash of the saved list in the database. The RememberThisList snippet can be triggered by the request parameter rememberthis containing this hash. That way remembered lists can be mailed to other users. |
RememberThisClear (FormIt hook)
The FormIt hook clears the list and can be used as one of the last entries in the FormIt hook list.
Order of FormIt and RememberThisList
If the list is cleared with the rememberClearList property or the RememberThisClear hook, call FormIt before the RememberThisList snippet on the form page. Otherwise the page shown after the submit still contains the old list.
System Settings
RememberThis uses the following system settings in the namespace rememberthis.
| Key | Name | Description |
Default |
|---|---|---|---|
| rememberthis.addTpl | Add Template | Template for the add link. | tplRememberThisAdd |
| rememberthis.ajaxLoaderImg | AJAX Loader Image | Image file, that is shown during AJAX requests. | - |
| rememberthis.classname | Classname | xPDO class name where the added data is retrieved from. | - |
| rememberthis.cookieExpireDays | Cookie Expiration | The expiration time of the cookie and the stored list after the last use (in days). | 90 |
| rememberthis.cookieName | Cookie Name | The name of the cookie. | rememberlist |
| rememberthis.debug | Debug | Display and log debug information. | No |
| rememberthis.fields | Fields | Comma-separated list of field names of the resource or xPDO class, that are remembered in the list. | - |
| rememberthis.includeCss | Include CSS | Include css (at the end of the head). | Yes |
| rememberthis.includeScripts | Include Javascripts | Include javascripts (at the end of the body). | Yes |
| rememberthis.itemTitleTpl | Item Title Template | Template for one list item. | tplRememberThisItemTitle |
| rememberthis.joins | Joins | Joins defined in the xPDO class, to retrieve the added data. | - |
| rememberthis.jQueryPath | Path to jQuery | Path to jQuery script. | - |
| rememberthis.keyname | Keyname | xPDO class keyname to retrieve one data row. | id |
| rememberthis.language | Language | The language of the AJAX responses (de or en). |
- |
| rememberthis.noResultsTpl | No Results Template | Template that is displayed, if the list is empty. | tplRememberThisNoResults |
| rememberthis.outerTpl | Outer Template | Outer template for the output of the list, if the list is not empty. | tplRememberThisOuter |
| rememberthis.packagename | Packagename | xPDO package name from which the added data is retrieved. If empty, the data is retrieved from resources. | - |
| rememberthis.queryAdd | Add Query Key | Query key, that is used to add elements to the list. | add |
| rememberthis.queryDelete | Delete Query Key | Query key, that is used to remove elements from the list. | delete |
| rememberthis.rowTpl | Row Template | Row template for the output of a list element. | tplRememberThisRow |
| rememberthis.scriptTpl | Script Template | Template for the javascript call. | tplRememberThisScript |
| rememberthis.showZeroCount | Show Zero Value | Show Zero Values in template. | Yes |
| rememberthis.tplPath | Templates Path | Base path for template chunks using @FILE binding. | {assets_path}elements/chunks/ |
| rememberthis.tvPrefix | Template Variable Prefix | Prefix for template variables in template chunks. | tv. |
| rememberthis.useCookie | Use Cookie | Keep the list on the server (in the MODX cache) and reference it with a cookie. | No |
| rememberthis.useDatabase | Use Database | Save the remembered list in the database (only for logged in frontend users). It expires 30 days after the last use. | No |
| rememberthis.where | Where Clause | JSON encoded xPDO where clause to filter the addable elements. Warning: If empty, every xPDO row or published resource can be added (Where Example). | - |
| rememberthis.wrapperTpl | Wrapper Template | Wrapper template for the outer output or the empty output. | tplRememberThisWrapper |
Multiple snippet calls and debug output
If you use the RememberThisList snippet call multiple times on a page, all snippet calls have to be different, to show the debug information.
The following templating system settings can be overridden by snippet properties: rowTpl, outerTpl, wrapperTpl, addTpl, noResultsTpl, tplPath
In the rowTpl template chunk all resource fields can be used as placeholder (template variables have to be prefixed using the prefix set in tvPrefix), if no xPDO package/classname is used. If a xPDO package/classname is used, all fields of the xPDO class can be used as placeholder.
The rememberthis.joins system setting can contain a JSON encoded array of join
options. Each join option has to contain the joined class, the alias of the
joined class (defaults to class), the prefix for each retrieved field of the
joined class and the conditions for the join.
Joins Example
[{"class":"<class_name>","alias":"<class_alias>","prefix":"<prefix>_","conditions":["<class_alias>.<fieldname> = <joining_class_alias>.<fieldname>"]}]
The setting can also contain a simple list of relation names, i.e.
["<alias>"]. The related object of each relation is retrieved then.
Where Example
The rememberthis.where system setting restricts the resources or objects that
can be added to the list. It contains a JSON encoded xPDO where clause.
Resources also have to be published and not deleted.
For a custom xPDO package, the columns of joined classes can be referenced with the join alias:
The clause is only checked when an element is added. If the setting does not contain valid JSON, nothing can be added.
Missing where setting
If rememberthis.where is empty, every row of a configured custom xPDO class
can be added to the list by its key, and every published, not deleted
resource, if no package/classname is used. A visitor can change the key in
the request, so the add links on your pages don't limit this. Set a where
clause, if some rows contain data that should not be visible to everyone.
-
Most of the settings for the snippet templates should be done in the MODX system settings, as they are used by the snippets and with Ajax. ↩
-
If an xPDO object package and a classname are used, the object is referenced by the column with the system setting
keyname. ↩ -
The placeholder rememberqueryadd is filled with the
queryAddsystem setting. ↩ -
The identifier is set by the
keynamesystem setting, if the xPDO object package and classname is used. ↩↩↩↩ -
In the
itemTitleTpltemplate chunk all column names of the xPDO object can be referenced by a placeholder with this name. Also, all properties can be referenced with the property name, i.e. a property set by[[+rememberqueryadd]]property_testcan be referenced with the placeholder[[+test]]. ↩↩