Ditto Snippet

Description

Aggregates documents to create blogs, article/news collections, and more,with full support for templating.

Author

Mark Kaplan for MODx CMF

Version

2.1.0

Summary
Ditto SnippetAggregates documents to create blogs, article/news collections, and more,with full support for templating.
Parameters
ditto_baseLocation of Ditto files
idUnique ID for this Ditto instance for connection with other scripts (like Reflect) and unique URL parameters
languagelanguage for defaults, debug, and error messages
formatOutput format to use
configLoad a custom configuration
debugOutput debugging information
phxUse PHx formatting
extendersLoad an extender which adds functionality to Ditto
Variables
extendersArray that can be added to by configs or formats to load that extender
placeholdersInitialize custom placeholders array for configs or extenders to add to
filtersHolds both the custom filters array for configs or extenders to add to and the parsed filters array.
orderByAn array that holds all criteria to sort the result set by.
idTypetype of IDs provided; can be either parents or documents
Parameters
parentsIDs of containers for Ditto to retrieve their children to &depth depth
documentsIDs of documents for Ditto to retrieve
Variables
IDsInternal variable which holds the set of IDs for Ditto to fetch
Parameters
depthNumber of levels deep to retrieve documents
paginatePaginate the results set into pages of &display length.
dateSourceSource of the [+date+] placeholder
dateFormatFormat the [+date+] placeholder in human readable form
displayNumber of documents to display in the results
totalNumber of documents to retrieve
showPublishedOnlyShow only published documents
showInMenuOnlyShow only documents visible in the menu
hideFoldersDon’t show folders in the returned results
hidePrivateDon’t show documents the guest or user does not have permission to see
seeThruUnpubSee through unpublished folders to retrive their children Used when depth is greater than 1
queryLimitNumber of documents to retrieve from the database, same as MySQL LIMIT
whereCustom MySQL WHERE statement
noResultsText or chunk to display when there are no results
removeChunkName of chunks to be stripped from content separated by commas
hiddenFieldsAllow Ditto to retrieve fields its template parser cannot handle such as nested placeholders and [fields]
startNumber of documents to skip in the results
globalFilterDelimiterFilter delimiter used to separate filters in the filter string
localFilterDelimiterDelimiter used to separate individual parameters within each filter string
filterRemoves items not meeting a critera.
keywordsEnable fetching of associated keywords for each document Can be used as [+keywords+] or as a tagData source
randomizeRandomize the order of the output
saveSaves the ditto object and results set to placeholders for use by other snippets
tplUser defined chunk to format the documents
tplAltUser defined chunk to format every other document
tplFirstUser defined chunk to format the first document
tplLastUser defined chunk to format the last document
tplCurrentDocumentUser defined chunk to format the current document
orderBySort the result set
paginateAlwaysShowLinksDetermine whether or not to always show previous next links
paginateSplitterCharacterSplitter to use if always show is disabled
tplPaginatePreviousTemplate for the previous link
tplPaginateNextTemplate for the next link
tplPaginateNextOffTemplate for the inside of the next link
tplPaginatePreviousOffTemplate for the previous link when it is off
tplPaginatePageTemplate for the page link
tplPaginateCurrentPageTemplate for the current page link
Placeholders
item[x]Individual items rendered output

Parameters

ditto_base

Purpose

Location of Ditto files

Options

Any valid folder location containing the Ditto source code with a trailing slash

Default

[(base_path)]assets/snippets/ditto/

id

Purpose

Unique ID for this Ditto instance for connection with other scripts (like Reflect) and unique URL parameters

Options

Any combination of characters a-z, underscores, and numbers 0-9

Note

This is case sensitive

Default

””blank

language

Purpose

language for defaults, debug, and error messages

Options

Any language name with a corresponding file in the &ditto_base/lang folder

Default

”english”

format

Purpose

Output format to use

Options

  • ”html”
  • ”json”
  • ”xml”
  • ”atom”
  • ”rss”

Default

”html”

config

Purpose

Load a custom configuration

Options

”default”default blank config file
CONFIG_NAMEOther configs installed in the configs folder or in any folder within the MODx base path via @FILE

Default

”default”

Related

debug

Purpose

Output debugging information

Options

0off
1on

Default

0off

Related

phx

Purpose

Use PHx formatting

Options

0off
1on

Default

1on

extenders

Purpose

Load an extender which adds functionality to Ditto

Options

Any extender in the extenders folder or in any folder within the MODx base path via @FILE

Default

[NULL]

Related

Variables

extenders

Array that can be added to by configs or formats to load that extender

placeholders

Initialize custom placeholders array for configs or extenders to add to

filters

Holds both the custom filters array for configs or extenders to add to and the parsed filters array.  To add to this array, use the following format

$filters["parsed"][] = array("name" => array("source"=>$source,"value"=>$value,"mode"=>$mode));
$filters["custom"][] = array("source","callback_function");

orderBy

An array that holds all criteria to sort the result set by.  Note that using a custom sort will disable all other sorting.

$orderBy["parsed"][] = array("sortBy","sortDir");
$orderBy["custom"][] = array("sortBy","callback_function");

idType

type of IDs provided; can be either parents or documents

Parameters

parents

Purpose

IDs of containers for Ditto to retrieve their children to &depth depth

Options

Any valid MODx document marked as a container

Default

Current MODx Document

Related

documents

Purpose

IDs of documents for Ditto to retrieve

Options

Any valid MODx document marked as a container

Default

None

Related

Variables

IDs

Internal variable which holds the set of IDs for Ditto to fetch

Parameters

depth

Purpose

Number of levels deep to retrieve documents

Options

Any number greater than or equal to 1 0 - infinite depth

Default

1

Related

paginate

Purpose

Paginate the results set into pages of &display length.  Use &total to limit the number of documents retreived.

Options

0off
1on

Default

0off

Related

dateSource

Purpose

Source of the [+date+] placeholder

Options

#Any UNIX timestamp from MODx fields or TVs such as createdon, pub_date, or editedon

Default

”createdon”

Related

dateFormat

Purpose

Format the [+date+] placeholder in human readable form

Options

Any PHP valid strftime option

Default

[LANG]

Related

display

Purpose

Number of documents to display in the results

Options

#Any number
”all”All documents found

Default

3

Related

total

Purpose

Number of documents to retrieve

Options

#Any number
”all”All documents found

Default

”all”All documents found

Related

showPublishedOnly

Purpose

Show only published documents

Options

0show only unpublished documents
1show both published and unpublished documents

Default

1show only published documents

Related

showInMenuOnly

Purpose

Show only documents visible in the menu

Options

0show all documents
1show only documents with the show in menu flag checked

Default

0show all documents

Related

hideFolders

Purpose

Don’t show folders in the returned results

Options

0keep folders
1remove folders

Default

0keep folders

Related

hidePrivate

Purpose

Don’t show documents the guest or user does not have permission to see

Options

0show private documents
1hide private documents

Default

1hide private documents

Related

seeThruUnpub

Purpose

See through unpublished folders to retrive their children Used when depth is greater than 1

Options

0off
1on

Default

0off

Related

queryLimit

Purpose

Number of documents to retrieve from the database, same as MySQL LIMIT

Options

#Any number
0automatic

Default

0automatic

Related

where

Purpose

Custom MySQL WHERE statement

Options

A valid MySQL WHERE statement using only document object items (no TVs)

Default

[NULL]

Related

noResults

Purpose

Text or chunk to display when there are no results

Options

Any valid chunk name or text

Default

[LANG]

removeChunk

Purpose

Name of chunks to be stripped from content separated by commas

  • Commonly used to remove comments

Options

Any valid chunkname that appears in the output

Default

[NULL]

hiddenFields

Purpose

Allow Ditto to retrieve fields its template parser cannot handle such as nested placeholders and [fields]

Options

Any valid MODx fieldnames or TVs comma separated

Default

[NULL]

start

Purpose

Number of documents to skip in the results

Options

Any number

Default

0

globalFilterDelimiter

Purpose

Filter delimiter used to separate filters in the filter string

Options

Any character not used in the filters

Default

”|”

Related

localFilterDelimiter

Purpose

Delimiter used to separate individual parameters within each filter string

Options

Any character not used in the filter itself

Default

”,”

Related

filter

Purpose

Removes items not meeting a critera.  Thus, if pagetitle == joe then it will be removed.  Use in the format field,criteria,mode with the comma being the local delimiter

Mode Meaning

1!=
2==
3<
4>
5<=
6>=
7Text not in field value
8Text in field value
9case insenstive version of #7
10case insenstive version of #8
11checks leading character of the field

@EVAL

@EVAL in filters works the same as it does in MODx exect it can only be used with basic filtering, not custom filtering (tagging, etc).  Make sure that you return the value you wish Ditto to filter by and that the code is valid PHP.

Default

[NULL]

Related

keywords

Purpose

Enable fetching of associated keywords for each document Can be used as [+keywords+] or as a tagData source

Options

0off
1on

Default

0off

randomize

Purpose

Randomize the order of the output

Options

0off
1on Any MODx field or TV for weighted random

Default

0off

save

Purpose

Saves the ditto object and results set to placeholders for use by other snippets

Options

0off; returns output
1remaining; returns output
2all;
3all; returns ph only

Default

0off; returns output

tpl

Purpose

User defined chunk to format the documents

Options

  • Any valid chunk name
  • Code via @CODE
  • File via @FILE

Default

[LANG]

tplAlt

Purpose

User defined chunk to format every other document

Options

  • Any valid chunk name
  • Code via @CODE
  • File via @FILE

Default

&tpl

tplFirst

Purpose

User defined chunk to format the first document

Options

  • Any valid chunk name
  • Code via @CODE
  • File via @FILE

Default

&tpl

tplLast

Purpose

User defined chunk to format the last document

Options

  • Any valid chunk name
  • Code via @CODE
  • File via @FILE

Default

&tpl

tplCurrentDocument

Purpose

User defined chunk to format the current document

Options

  • Any valid chunk name
  • Code via @CODE
  • File via @FILE

Default

&tpl

orderBy

Purpose

Sort the result set

Options

Any valid MySQL style orderBy statement

Default

createdon DESC

paginateAlwaysShowLinks

Purpose

Determine whether or not to always show previous next links

Options

0off
1on

Default

0off

Related

paginateSplitterCharacter

Purpose

Splitter to use if always show is disabled

Options

Any valid character

Default

[LANG]

Related

tplPaginatePrevious

Purpose

Template for the previous link

Options

  • Any valid chunk name
  • Code via @CODE
  • File via @FILE

Placeholders

urlURL for the previous link
lang:previousvalue of ‘prev’ from the language file

Related

tplPaginateNext

Purpose

Template for the next link

Options

  • Any valid chunk name
  • Code via @CODE
  • File via @FILE

Placeholders

urlURL for the next link
lang:nextvalue of ‘next’ from the language file

Related

tplPaginateNextOff

Purpose

Template for the inside of the next link

Options

  • Any valid chunk name
  • Code via @CODE
  • File via @FILE

Placeholders

lang:nextvalue of ‘next’ from the language file

Related

tplPaginatePreviousOff

Purpose

Template for the previous link when it is off

Options

  • Any valid chunk name
  • Code via @CODE
  • File via @FILE

Placeholders

lang:previousvalue of ‘prev’ from the language file

Related

tplPaginatePage

Purpose

Template for the page link

Options

  • Any valid chunk name
  • Code via @CODE
  • File via @FILE

Placeholders

urlurl for the page
pagenumber of the page

Related

tplPaginateCurrentPage

Purpose

Template for the current page link

Options

  • Any valid chunk name
  • Code via @CODE
  • File via @FILE

Placeholders

pagenumber of the page

Related

Placeholders

item[x]

Content

Individual items rendered output

Load an extender which adds functionality to Ditto
Output debugging information
Load a custom configuration
IDs of documents for Ditto to retrieve
Number of levels deep to retrieve documents
IDs of containers for Ditto to retrieve their children to &depth depth
See through unpublished folders to retrive their children Used when depth is greater than 1
Determine whether or not to always show previous next links
Splitter to use if always show is disabled
Number of documents to display in the results
Format the [+date+] placeholder in human readable form
Source of the [+date+] placeholder
Number of documents to retrieve from the database, same as MySQL LIMIT
Number of documents to retrieve
Don’t show folders in the returned results
Show only published documents
Custom MySQL WHERE statement
Show only documents visible in the menu
Delimiter used to separate individual parameters within each filter string
Removes items not meeting a critera.
function parseFilters($filter = false,
$cFilters = false,
$pFilters =  false,
$globalDelimiter,  
$localDelimiter  )
Split up the filters into an array and add the required fields to the fields array
Filter delimiter used to separate filters in the filter string
Paginate the results set into pages of &display length.
Template for the next link
Template for the previous link