### Setup Options PHP File Source: https://github.com/modxorg/docs/blob/3.x/en/extending-modx/tutorials/developing-an-extra/part-3.md Defines the content to be displayed in the setup options dialog during installation. This example shows a welcome message. ```php Doodles Installer

Thanks for installing Doodles! Please review the setup options below before proceeding.


'; break; case xPDOTransport::ACTION_UPGRADE: case xPDOTransport::ACTION_UNINSTALL: break; } return $output; ``` -------------------------------- ### Build Setup Options Form Source: https://github.com/modxorg/docs/blob/3.x/en/extending-modx/transport-packages/build-script.md This PHP script generates an HTML form for package setup options. It dynamically sets default values and retrieves existing system settings for 'install' and 'upgrade' actions, returning the HTML output. ```php 'my@emailhere.com', 'emailsFrom' => 'my@emailhere.com', 'emailsReplyTo' => 'my@emailhere.com', ); switch ($options[xPDOTransport::PACKAGE_ACTION]) { case xPDOTransport::ACTION_INSTALL: case xPDOTransport::ACTION_UPGRADE: $setting = $modx->getObject('modSystemSetting',array('key' => 'quip.emailsTo')); if ($setting != null) { $values['emailsTo'] = $setting->get('value'); } unset($setting); $setting = $modx->getObject('modSystemSetting',array('key' => 'quip.emailsFrom')); if ($setting != null) { $values['emailsFrom'] = $setting->get('value'); } unset($setting); $setting = $modx->getObject('modSystemSetting',array('key' => 'quip.emailsReplyTo')); if ($setting != null) { $values['emailsReplyTo'] = $setting->get('value'); } unset($setting); break; case xPDOTransport::ACTION_UNINSTALL: break; } $output = '



'; return $output; ``` -------------------------------- ### Wayfinder &startItemTpl Example Source: https://github.com/modxorg/docs/blob/3.x/en/extras/wayfinder/index.md Example of how &startItemTpl can be used to format the start item in a Wayfinder menu. This snippet defines a heading for the start item with a link. ```php [+wf.wrapper+] ``` -------------------------------- ### Get Custom Service with Parameters Source: https://github.com/modxorg/docs/blob/3.x/en/extending-modx/modx-class/reference/modx.getservice.md This example shows how to load a custom user-defined service, specifying its class name, path, and constructor parameters. It then calls a method on the loaded service. ```php $modx->getService('twitter','modTwitter','/path/to/',array( 'api_key' => 3212423, )); $modx->twitter->tweet('Success!'); ``` -------------------------------- ### Alternative config.core.php Setup Source: https://github.com/modxorg/docs/blob/3.x/en/extending-modx/tutorials/developing-an-extra/part-2.md In specific development environments, you might need to define MODX paths manually. Ensure these paths are correct for your installation and add them to your ignore file. ```php xpdo) { /* @var modX $modx */ $modx = &$object->xpdo; switch ($options[xPDOTransport::PACKAGE_ACTION]) { case xPDOTransport::ACTION_INSTALL: // Actions on first package installation break; case xPDOTransport::ACTION_UPGRADE: // Actions when updating a package break; case xPDOTransport::ACTION_UNINSTALL: // What to do when removing a package break; } } return true; ``` -------------------------------- ### Example @SELECT Binding for Users Source: https://github.com/modxorg/docs/blob/3.x/en/building-sites/elements/template-variables/bindings/select-binding.md This example demonstrates how to retrieve a list of active usernames and their IDs from the 'users' table to populate a dropdown. ```sql @SELECT `username` AS `name`,`id` FROM `[[+PREFIX]]users` WHERE `active` = 1 ``` -------------------------------- ### Install and Build with Gitify Source: https://github.com/modxorg/docs/blob/3.x/en/extras/fred/collab/pr_workflow.md Use Gitify to install all packages and build the project after syncing with the upstream remote. This is typically done after updating your local repository. ```shell gitify package:install --all gitify build ``` -------------------------------- ### Initialize and Use modRest Client Source: https://github.com/modxorg/docs/blob/3.x/en/extending-modx/services/modrest.md Demonstrates how to get the modRest service and make basic GET or POST requests. The response can be processed into an array. ```php /* @var modRest $client */ $client = $modx->getService('rest', 'rest.modRest'); $response = $client->get('GET request'); # or $response = $client->post('POST request'); // Processing the received data in json or xml format and converting them into an array $array = $response->process(); ``` -------------------------------- ### data-fred-min-width Example Source: https://github.com/modxorg/docs/blob/3.x/en/extras/fred/themer/elements/attributes.md Example of setting a minimum width for a dropzone using data-fred-min-width. ```html
``` -------------------------------- ### Install a Transport Package Source: https://github.com/modxorg/docs/blob/3.x/en/extending-modx/xpdo/class-reference/xpdotransport/xpdotransport.install.md Use this method to install a transport package. It accepts an optional array of options. ```php $transport->install(); ``` -------------------------------- ### Simple Chunk Example Source: https://github.com/modxorg/docs/blob/3.x/en/extending-modx/snippets/good-chunk.md This example demonstrates a clean and simple Chunk template for displaying a greeting. It uses placeholders for dynamic content. ```php Dear [[+first_name]], it was nice to see you last [[+day_of_week]] ``` -------------------------------- ### Install Composer and Gitify Source: https://github.com/modxorg/docs/blob/3.x/en/extras/fred/collab/gitify.md Execute these commands via SSH to install Composer and clone the Gitify repository into your site's home directory. ```shell cd www; curl http://modx.co/scripts/install.sh | sh mkdir ../gitify; cd ../gitify git clone https://github.com/modmore/Gitify.git ./ ``` -------------------------------- ### Install and Build Theme with Gitify Source: https://github.com/modxorg/docs/blob/3.x/en/extras/fred/collab/gitify.md Use Gitify commands to install all associated packages for the theme and then build the theme within your MODX instance. ```shell cd ~/www gitify package:install --all gitify build ``` -------------------------------- ### Permanent Sort Syntax Example Source: https://github.com/modxorg/docs/blob/3.x/en/extras/collections/index.md An example demonstrating how to configure permanent sort settings. This specific example sorts unpublished resources to the top when the grid is sorted by 'publishedon' in ascending order, ensuring unpublished items are always prioritized. ```plain publishedon=published:asc -- Setting above as Permanent sort - Before will pull all unpublished resources on top of the grid when sorting by published on. Because sort_dir is present, doesn't matter if you sorting asc/desc by published on, unpublished resources will always be on top. ``` -------------------------------- ### Example Template List Entry Source: https://github.com/modxorg/docs/blob/3.x/en/extras/tinymce/tinymce.template.md An example of how to format a single template entry in the 'Template List' setting. Multiple templates can be added, separated by commas. ```php name:path-to-the-template:description ``` -------------------------------- ### Extension Packages Setting Example Source: https://github.com/modxorg/docs/blob/3.x/en/extending-modx/custom-resources/index.md An example of how the 'extension_packages' system setting might look after a custom package has been added. It shows the package name and its model path. ```json [{"copyrightedresource":{"path":"[[++core_path]]components/copyrightedresource/model/"}}] ``` -------------------------------- ### Send Parameter Example Source: https://github.com/modxorg/docs/blob/3.x/en/extras/geturlparam/index.md This example shows how to send a parameter named 'val' with the value '5' to a resource with ID 10. ```MODX [[~10? &val=`5`]] ``` -------------------------------- ### xPDOQuery::limit() Example Source: https://github.com/modxorg/docs/blob/3.x/en/extending-modx/xpdo/class-reference/xpdoquery/xpdoquery.limit.md This example demonstrates how to fetch a specific range of records, such as the second set of 10 boxes, by using the limit and offset parameters. ```php $query = $xpdo->newQuery('Box'); $query->limit(10,10); $boxes = $xpdo->getCollection('Box',$query); ``` -------------------------------- ### Radio Options Sidebar Example Source: https://github.com/modxorg/docs/blob/3.x/en/building-sites/elements/template-variables/input-types/index.md An advanced usage example for Radio Options TV, using chunk placeholders as values to dynamically output content. ```php [[$my_related_chunk]]||Content==[[*sidebar-txt]]||Twitter==[[$my_twitter_chunk]] ``` -------------------------------- ### Get Field from Ultimate Parent Resource Source: https://github.com/modxorg/docs/blob/3.x/en/extras/getresourcefield/index.md Retrieves the 'introtext' field from the ultimate parent resource. This example requires the 'UltimateParent' snippet to be installed and functional. ```php [[getResourceField? &id=`[[UltimateParent]]` &field=`introtext`]] ``` -------------------------------- ### Get Family Comments with Limit Source: https://github.com/modxorg/docs/blob/3.x/en/extras/quip/quip.quiprss.md This example fetches the latest 20 comments from threads whose names start with 'blog-post' using the 'family' and 'limit' properties. This is useful for grouping comments by a common prefix. ```php [[!QuipRss? &type=`family` &family=`blog-post` &limit=`10`]] ``` -------------------------------- ### Handle New and Update Modes Source: https://github.com/modxorg/docs/blob/3.x/en/extending-modx/plugins/system-events/onbeforedocformsave.md A comprehensive example showing how to handle both new resource creation and updates. It checks for the 'introtext' field on updates and prevents new resource creation entirely. ```php event->name; switch($eventName) { case 'OnBeforeDocFormSave': if ($mode == modSystemEvent::MODE_UPD) { //if not filled introtext if (!$resource->get('introtext')){ $modx->event->output("You have not forgotten your head at home, but you have forgotten about the 'Keywords'!"); } } elseif ($mode == modSystemEvent::MODE_NEW) { $modx->event->output("You cannot create resources!"); } break; } ``` -------------------------------- ### Run a Snippet with Parameters Source: https://github.com/modxorg/docs/blob/3.x/en/extending-modx/modx-class/reference/modx.runsnippet.md Execute the 'Welcome' snippet and pass a 'name' parameter to it. The output of the snippet is then echoed. ```php $output = $modx->runSnippet('Welcome',array( 'name' => 'John' )); echo $output; // prints 'Welcome John!' ``` -------------------------------- ### Set up Gitify CLI Source: https://github.com/modxorg/docs/blob/3.x/en/extras/fred/collab/gitify.md After installing Gitify, run composer install to manage dependencies, make the Gitify script executable, and create a symbolic link for easy access. ```shell cd ~/gitify composer install chmod +x Gitify; cd ~/.bin; ln -s ../gitify/Gitify gitify ``` -------------------------------- ### Eletter Trigger/Response Snippet Example Source: https://github.com/modxorg/docs/blob/3.x/en/extras/eletters/eletters.api.md This PHP snippet demonstrates how to use the Eletters API to send an email to the currently logged-in MODX user. It includes setup for the Eletters service and defines options for the email recipient and content. Ensure the Eletters component is installed and configured. ```php eletters)) { $modx->addPackage('eletters', $modx->getOption('core_path').'components/eletters/model/'); $modx->eletters = $modx->getService('eletters', 'Eletters', $modx->getOption('core_path').'components/eletters/model/eletters/'); } $eletters =& $modx->eletters; $profile = $modx->user->getOne('Profile'); $to = $to_name = ''; if ( is_object($profile) ) { $to = $profile->get('email'); $to_name = $profile->get('fullname'); } else { return 'Cannot find MODX user'; } $options = array( 'to_address' => $to, 'to_name' => $to_name, 'EResourceID' => 10, ); $placeholders = $profile->toArray(); /** * * @param (Array) $options - name=>value ex: for auto response form_address=Fname Lname * 'from_address' => '', 'from_name' => '', 'to_address' => '', 'to_name' => '', 'cc_address' => '', 'cc_name' => '', 'bcc_address' => '', 'bcc_name' => '', 'reply_to_address' => '', 'reply_to_name' => '', 'ishtml' => TRUE, 'NewsletterID' => '', 'EResourceID' => '', 'uploads' => TRUE, 'files' => TRUE, * @param (Array) $placeholders - MODX placehoders -name=>value * @param (Boolean) $log - TRUE will save completed email to DB * @param (Array) $attachments - add addtional attachments */ $sent = $eletters->sendResponse($options, $placeholders, $log=TRUE); $output = ''; if ( $sent ) { $output = 'An email was sent to '.$to_name.' at '.$to.' email address.'; } else { $output = 'An email could not be sent to '.$to_name.' at '.$to.' email address.'; } return $output; ``` -------------------------------- ### Wildcard Search: Starts With Source: https://github.com/modxorg/docs/blob/3.x/en/extras/renderresources/index.md Use a wildcard (%) at the end to match TV values that start with a specific string. This example matches 'mytv' values starting with 'a'. ```php mytv==a% ``` -------------------------------- ### Get a Cache Provider Instance Source: https://github.com/modxorg/docs/blob/3.x/en/extending-modx/xpdo/class-reference/xpdocachemanager/xpdocachemanager.getcacheprovider.md Retrieve a specific cache provider instance from the cache manager. This example shows how to get an instance of the xPDOMemCache provider. ```php $cacheManager = $xpdo->getCacheManager(); $provider = $cacheManager->getCacheProvider('xPDOMemCache'); ``` -------------------------------- ### Initialize Build Script and Timer Source: https://github.com/modxorg/docs/blob/3.x/en/extending-modx/transport-packages/build-script.md Starts the build script with PHPDoc comments and a timer. Sets the script to not time out. ```php getSessionContexts(); print_r($keys); // prints Array ( 'web', 'mgr' ); ``` -------------------------------- ### Simple Example Form with FormItFastPack Source: https://github.com/modxorg/docs/blob/3.x/en/extras/formitfastpack/formitfastpack.field.md This example demonstrates a complete form using FormIt and the field snippet for various input types. It includes text, checkbox, select, textarea, and submit fields. ```php [[!FormIt? &prefix=`myprefix.` &submitVar=`submitForm`]]
[[!fieldSetDefaults? &prefix=`myprefix.` &outer_tpl=`myWrapTpl` &resetDefaults=`1`]] [[!field? &name=`full_name` &type=`text` &class=`required`]] [[!field? &name=`favorite_color` &type=`checkbox` &options=`Blue||Red||Yellow`]] [[!field? &name=`location` &type=`select` &label=`Where are you from?` &options=`United States==US||New Zealand==NZ||Never Never Land==NNL`]] [[!field? &name=`message` &type=`textarea`]] [[!field? &name=`submitForm` &type=`submit` &label=` ` &message=`Submit Form`]]
``` -------------------------------- ### xPDO Package Loading and Data Interaction Example Source: https://github.com/modxorg/docs/blob/3.x/en/extending-modx/xpdo/index.md Demonstrates loading a custom package, retrieving and creating objects, building complex queries with conditions and sorting, and iterating through results with related object retrieval. Note that direct echo statements should be avoided in production code; data should ideally be passed to templates. ```php if (!$modx->addPackage('education', '/path/to/model/')) { die('Can\'t load package, try again later.'); } // Get into Harvard (or create a new school with the same name) $school = $modx->getObject('School', ['name' => 'Harvard']); if (!$school) { $school = $modx->newObject('School'); $school->set('name', 'Harvard'); $school->save(); } // Find the 100 students that are alumni and sort by lastname $c = $modx->newQuery('Student'); $c->where([ 'school' => $school->get('id'), 'is_alumni' => true, 'start_year' => $_GET['start_year'] ?? date('Y') - 5, ]); $c->sortby('lastname', 'ASC'); $c->limit(100); foreach ($modx->getIterator('Student', $c) as $student) { echo $student->get('firstname') . ' ' . $student->get('lastname') . ' started studying in ' . $student->get('start_year'); if ($graduation = $student->getOne('Graduation')) { echo ' and graduated in ' . $graduation->get('year') . ".\n"; } else { echo " and has not graduated.\n"; } } ``` -------------------------------- ### Get Facebook Comments for a Resource in getResources Source: https://github.com/modxorg/docs/blob/3.x/en/extras/socialsuite/socialsuite.getfacebookshares.md This example shows how to get Facebook comment counts for a specific resource within a getResources template. It dynamically generates the full URL for the resource. ```php Comments: [[!getFacebookShares? &node=`comments` &url=`[[~[[+id]]? &scheme=`full`]]`]] ``` -------------------------------- ### Example getResources Snippet Source: https://github.com/modxorg/docs/blob/3.x/en/building-sites/client-proofing/form-customization/rules/field-default.md This is an example of a MODX Revolution snippet call to get resources. It is used here to illustrate the context in which a Field Default Rule might be applied, though it does not directly demonstrate the rule itself. ```php [[getResources@section? &parents=`122` &context=`revolution`]] ``` -------------------------------- ### Create a Simple Ext JS Panel Source: https://github.com/modxorg/docs/blob/3.x/en/extending-modx/custom-manager-pages/modext/modext-tutorials/5.-ext-js-tutorial-panels.md This example shows how to create and render a basic Ext JS panel. Ensure Ext JS libraries are loaded before this script. ```html Ext JS Panels

Panels

``` -------------------------------- ### Get Controller Path Example Source: https://github.com/modxorg/docs/blob/3.x/en/extending-modx/custom-resources/step-3-controllers.md This snippet shows how to retrieve the core path for custom component controllers. ```php return $modx->getOption('copyrightedresource.core_path',null,$modx->getOption('core_path').'components/copyrightedresource/').'controllers/'; ``` -------------------------------- ### Copy Build Configuration Files Source: https://github.com/modxorg/docs/blob/3.x/en/getting-started/installation/git.md Navigate to the _build directory and copy the sample configuration files to their active counterparts. These files typically do not require modification unless database connection settings need to be changed. ```bash cd www/_build cp build.config.sample.php build.config.php cp build.properties.sample.php build.properties.php ``` -------------------------------- ### Load a class with options and instantiate Source: https://github.com/modxorg/docs/blob/3.x/en/extending-modx/xpdo/class-reference/xpdo/xpdo.loadclass.md Loads a class file, optionally ignoring package information and treating it as transient. If loading fails, it exits with an error message. The class is then instantiated. ```php if (!$xpdo->loadClass('myBox','/my/path/to/model/',true,true)) { die('Could not load class myBox!'); } $Box = new myBox(); ``` -------------------------------- ### Fenom Global Variables Access Source: https://github.com/modxorg/docs/blob/3.x/en/extras/pdoTools/Parser.md Examples of accessing global variables like session, GET, and SERVER using Fenom. ```php {$.session['your_key']} {$.get['query']} or {$.get.query} {$.server['REQUEST_URI']} ``` -------------------------------- ### Loading a Package from FormIt Components Source: https://github.com/modxorg/docs/blob/3.x/en/extending-modx/xpdo/class-reference/xpdo/xpdo.addpackage.md Illustrates loading a package from a specific component's model directory, using FormIt's structure as an example. ```php $xpdo->addPackage('recaptcha', MODX_CORE_PATH.'components/formit/model/'); ``` -------------------------------- ### Get Site Start Page ID Source: https://github.com/modxorg/docs/blob/3.x/en/building-sites/tag-syntax/common.md Retrieves the ID of the designated home page. Useful for creating links to the home page. ```html ``` -------------------------------- ### modX.initialize Source: https://github.com/modxorg/docs/blob/3.x/en/extending-modx/modx-class/index.md Initializes the MODX environment. ```APIDOC ## modX.initialize ### Description Initializes the MODX environment. ### Method Not specified (typically called via JavaScript or PHP within MODX). ### Parameters * **contextKey** (string, optional) - The key of the context to initialize with. ``` -------------------------------- ### Register JS to the start of the page Source: https://github.com/modxorg/docs/blob/3.x/en/extending-modx/modx-class/reference/modx.regclientstartupscript.md Registers a JavaScript file to be included in the HEAD section of the page. This example shows how to register a local asset. ```php $modx->regClientStartupScript('assets/js/onload.js'); ``` -------------------------------- ### Example MODX Snippet with Documentation Source: https://github.com/modxorg/docs/blob/3.x/en/extending-modx/snippets/good-snippet.md This snippet demonstrates good practices including a detailed comment block with description, properties, and usage examples, along with input validation and logging. ```php getOption('x', $scriptProperties); $y = (int) $modx->getOption('y', $scriptProperties); $z = (int) $modx->getOption('z', $scriptProperties, 1); // For debugging: $modx->log(modX::LOG_LEVEL_DEBUG , '[mySnippet] called on page '. $modx->resource->id . ' with the following properties: ' .print_r($scriptProperties, true)); // Verify Inputs if (!isset($scriptProperties['x']) || !isset($scriptProperties['y'])) { $modx->log(modX::LOG_LEVEL_ERROR, '[mySnippet] missing required properties &x and &y!'); return; } return $x * $y * $z; ?> ``` -------------------------------- ### FastField Superglobal Arrays Source: https://github.com/modxorg/docs/blob/3.x/en/extras/pdoTools/Parser.md Examples of using FastField tags to access data from superglobal arrays like POST, SESSION, GET, etc. ```php [[#POST.key]] [[#SESSION.another_key]] [[#GET.key3]] [[#REQUEST.key]] [[#SERVER.key]] [[#FILES.key]] [[#COOKIE.some_key]] ``` -------------------------------- ### Initialize MODX and Package Builder Source: https://github.com/modxorg/docs/blob/3.x/en/extending-modx/transport-packages/build-script.md Sets up the MODX environment and initializes the package builder for creating a MODX transport package. Includes setting log level and target. ```php $root, 'build' => $root .'_build/', 'lexicon' => $root . '_build/lexicon/', 'resolvers' => $root . '_build/resolvers/', 'data' => $root . '_build/data/', 'source_core' => $root.'core/components/quip', 'source_assets' => $root.'assets/components/quip', 'docs' => $root.'core/components/quip/docs/', ); unset($root); /* override with your own defines here (see build.config.sample.php) */ require_once dirname(__FILE__) . '/build.config.php'; require_once MODX_CORE_PATH . 'model/modx/modx.class.php'; $modx= new modX(); $modx->initialize('mgr'); $modx->setLogLevel(modX::LOG_LEVEL_INFO); $modx->setLogTarget(XPDO_CLI_MODE ? 'ECHO' : 'HTML'); $modx->loadClass('transport.modPackageBuilder','',false, true); $builder = new modPackageBuilder($modx); $builder->createPackage('quip','0.1','alpha5'); $builder->registerNamespace('quip',false,true,'{core_path}components/quip/'); ``` -------------------------------- ### Get Tree for a Specific Resource Source: https://github.com/modxorg/docs/blob/3.x/en/extending-modx/modx-class/reference/modx.gettree.md Retrieves the resource tree starting from a specific resource ID (e.g., 12) and limits the depth to 5 levels. ```php $treeArray = $modx->getTree(12,5); ``` -------------------------------- ### Full xPDO ORM Example with Relations and getIterator Source: https://context7.com/modxorg/docs/llms.txt Demonstrates loading a custom package, querying objects with relations, creating new objects, and using getIterator for memory-efficient iteration over large result sets. Ensure the custom package is correctly registered. ```php addPackage('education', MODX_CORE_PATH . 'components/education/model/')) { return 'Could not load education package.'; } // Get or create a School object $school = $modx->getObject('School', ['name' => 'MODX Academy']); if (!$school) { $school = $modx->newObject('School'); $school->set('name', 'MODX Academy'); $school->save(); } // Query students with filtering, sorting, and limiting $c = $modx->newQuery('Student'); $c->where([ 'school' => $school->get('id'), 'is_alumni' => true, 'start_year' => ['>=', date('Y') - 5], ]); $c->sortby('lastname', 'ASC'); $c->limit(100); // getIterator is memory-efficient for large result sets $rows = ''; foreach ($modx->getIterator('Student', $c) as $student) { $data = $student->toArray(); // Load a related object (defined via schema relation) if ($graduation = $student->getOne('Graduation')) { $data['graduation_year'] = $graduation->get('year'); } $rows .= $modx->getChunk('studentRow', $data); } return ''; ``` -------------------------------- ### Get a Specific Context Source: https://github.com/modxorg/docs/blob/3.x/en/extending-modx/modx-class/reference/modx.getcontext.md This example demonstrates how to retrieve a context object by its unique key. The retrieved context is cached for subsequent use within the same request. ```php $ctx = $modx->getContext('sports'); ``` -------------------------------- ### Display User Gallery with Custom Templates Source: https://github.com/modxorg/docs/blob/3.x/en/extras/sekusergalleries/sekusergalleries.users.gallery.view.md This example shows how to specify custom templates for the gallery and album list. Ensure the specified template chunks exist. ```php [[!users.gallery.view? &tplGallery=`users.gallery.view` &tplAlbumList=`users.gallery.albumlist`]] ``` -------------------------------- ### Display Latest Comments by Family with Limit Source: https://github.com/modxorg/docs/blob/3.x/en/extras/quip/quip.quiplatestcomments.md This example fetches the latest comments from threads whose names start with a specific string ('blog-post') and limits the results. It uses the 'family' and 'limit' properties. ```php [[!QuipLatestComments? &type=`family` &family=`blog-post` &limit=`10`]] ``` -------------------------------- ### Apply prettyNumbers Output Filter to a MODX Tag Source: https://github.com/modxorg/docs/blob/3.x/en/extras/socialsuite/socialsuite.prettynumbers.md Use the prettyNumbers output filter directly on a MODX tag that outputs a number to format it nicely. No additional setup is required if SocialSuite is installed. ```php [[+count:prettyNumbers]] ``` -------------------------------- ### Set up Archives Resource Source: https://github.com/modxorg/docs/blob/3.x/en/building-sites/tutorials/creating-a-blog.md Configure the Archives page using getPage to fetch and display blog posts, with results stored in a placeholder. Includes pagination. ```php [[!getPage? &element=`getArchives` &elementClass=`modSnippet` &tpl=`blogPost` &hideContainers=`1` &pageVarKey=`page` &parents=`34,35` &includeTVs=`1` &toPlaceholder=`archives` &limit=`10` &cache=`0` ]]

[[+arc_month_name]] [[+arc_year]] Archives

[[+archives]][[!+page.nav:notempty=` `]] ``` -------------------------------- ### ExerPlan Snippet Examples Source: https://github.com/modxorg/docs/blob/3.x/en/extras/exerplan/index.md Demonstrates the usage of ExerPlan snippets like Galleries and Assessments. Ensure to uncomment the '_toArray' property to enable it. ```php [[!Login]]
[[!exerplan.Galleries? &requireAuth=`1` &userId=`[[+modx.user.id]]` &galleryMediatype=`video` &_toArray=`1` ]] [[!exerplan.Assessments? &requireAuth=`1` &assesseeId=`[[+modx.user.id]]` &_toArray=`1` ]] ``` -------------------------------- ### Multiple xPDO Connections (Read-Only) Source: https://github.com/modxorg/docs/blob/3.x/en/extending-modx/xpdo/create-xpdo-instance/connections.md Configure multiple database connections for an xPDO instance, including read-only options for master/slave setups. This example initializes with a mutable connection and defines two additional read-only connections. ```php $xpdo = new xPDO('mysql:host=127.0.0.1:19570;dbname=xpdotest;charset=utf8', 'username', 'password' array( xPDO::OPT_CONN_MUTABLE => true, xPDO::OPT_CONN_INIT => array(xPDO::OPT_CONN_MUTABLE => false), xPDO::OPT_CONNECTIONS => array( array( 'dsn' => 'mysql:host=127.0.0.1:19571;dbname=xpdotest;charset=utf8', 'username' => 'username', 'password' => 'password', 'options' => array( xPDO::OPT_CONN_MUTABLE => false, ), 'driverOptions' => array(), ), array( 'dsn' => 'mysql:host=127.0.0.1:19572;dbname=xpdotest;charset=utf8', 'username' => 'username', 'password' => 'password', 'options' => array( xPDO::OPT_CONN_MUTABLE => false, ), 'driverOptions' => array(), ), ), )); ``` -------------------------------- ### Get Thread Comments with Custom Body Limit Source: https://github.com/modxorg/docs/blob/3.x/en/extras/quip/quip.quiprss.md This example demonstrates how to fetch comments for a specific thread ('thread32') and truncate the comment body to 100 characters using the 'bodyLimit' property. This is useful for concise RSS previews. ```php [[!QuipRss? &type=`thread` &thread=`thread32` &bodyLimit=`100`]] ``` -------------------------------- ### Retrieve System Settings by Key Prefix Source: https://github.com/modxorg/docs/blob/3.x/en/building-sites/settings/index.md Constructs an xPDOQuery to find system settings whose keys match a specific prefix (e.g., 'quip.%'). It then retrieves these settings using getCollection and prints their values. ```php $query = $modx->newQuery('modSystemSetting'); $query->where(array('key:LIKE' => 'quip.%') ); $relatedSettings = $modx->getCollection('modSystemSetting', $query); foreach ( $relatedSettings as $Setting ) { print $Setting->get('value'); } ``` -------------------------------- ### Load pdoFetch Service Source: https://github.com/modxorg/docs/blob/3.x/en/extras/pdoTools/Classes/pdoFetch.md Instantiate the pdoFetch service. This is the first step before using any of its methods. ```php $pdo = $modx->getService('pdoFetch'); ``` -------------------------------- ### Get PK Type of a Resource Source: https://github.com/modxorg/docs/blob/3.x/en/extending-modx/xpdo/class-reference/xpdoobject/metadata-accessors/getpktype.md Retrieve the primary key type for a Resource object. This example demonstrates fetching a Resource by its ID and then calling getPKType() to output its primary key's data type, which is typically 'integer' for auto-increment IDs. ```php $resource = $xpdo->getObject('Resource',1); echo $resource->getPKType(); // prints "integer" ``` -------------------------------- ### Example Usage of getResources for Head Append Source: https://github.com/modxorg/docs/blob/3.x/en/extras/boilerx/bx-head-append.md This example demonstrates how to use the getResources snippet to fetch resources and potentially append them to the head. It specifies parent, context, limit, and a list of resources. ```php [[getResources@section? &parents=`1316` &context=`extras` &limit=`0` &resources=`1316,[[*id]]` ]] ``` -------------------------------- ### Resolve Setup Options in MODX Transport Package Source: https://github.com/modxorg/docs/blob/3.x/en/extending-modx/transport-packages/build-script.md This PHP script resolver processes setup-options during package installation or upgrade. It updates system settings based on provided options like emailsTo, emailsFrom, and emailsReplyTo. It logs errors if settings cannot be found. ```php xpdo->getObject('modSystemSetting',array('key' => 'quip.emailsTo')); if ($setting != null) { $setting->set('value',$options['emailsTo']); $setting->save(); } else { $object->xpdo->log(xPDO::LOG_LEVEL_ERROR,'[Quip] emailsTo setting could not be found, so the setting could not be changed.'); } /* emailsFrom */ $setting = $object->xpdo->getObject('modSystemSetting',array('key' => 'quip.emailsFrom')); if ($setting != null) { $setting->set('value',$options['emailsFrom']); $setting->save(); } else { $object->xpdo->log(xPDO::LOG_LEVEL_ERROR,'[Quip] emailsFrom setting could not be found, so the setting could not be changed.'); } /* emailsReplyTo */ $setting = $object->xpdo->getObject('modSystemSetting',array('key' => 'quip.emailsReplyTo')); if ($setting != null) { $setting->set('value',$options['emailsReplyTo']); $setting->save(); } else { $object->xpdo->log(xPDO::LOG_LEVEL_ERROR,'[Quip] emailsReplyTo setting could not be found, so the setting could not be changed.'); } $success= true; break; case xPDOTransport::ACTION_UNINSTALL: $success= true; break; } return $success; ``` -------------------------------- ### Basic FormIt Form with FormitFastPack Fields Source: https://github.com/modxorg/docs/blob/3.x/en/extras/formitfastpack/index.md This example demonstrates a basic FormIt form utilizing the 'field' snippet for generating input elements. Ensure FormIt and FormitFastPack are installed. The 'field' snippet handles dynamic values like current field values and error messages. ```html [[!FormIt? &hooks=`email,redirect` &emailTpl=`ContactFormReport` &emailTo=`[[++emailsender]]` &emailSubject=`New contact form submission` &validate=`email:email:required,message:required` &redirectTo=`1` ]]
[[!field? &type=`text` &name=`email` &req=`1`]] [[!field? &type=`textarea` &name=`message` &class=`cleardefault` &req=`1`]] [[!field? &type=`submit` &name=`submitForm` &label=` ` &message=`Send this Message!`]]
``` -------------------------------- ### Complete MODX Snippet Example Source: https://github.com/modxorg/docs/blob/3.x/en/extending-modx/tutorials/developing-an-extra/index.md This snippet demonstrates loading a custom service class, setting default properties, querying the database, and iterating through results to output content using file-based chunks. ```php getService('doodles','Doodles',$modx->getOption('doodles.core_path',null,$modx->getOption('core_path').'components/doodles/').'model/doodles/',$scriptProperties); if (!($dood instanceof Doodles)) return ''; /* setup default properties */ $tpl = $modx->getOption('tpl',$scriptProperties,'rowTpl'); $sort = $modx->getOption('sort',$scriptProperties,'name'); $dir = $modx->getOption('dir',$scriptProperties,'ASC'); /* build query */ $c = $modx->newQuery('Doodle'); $c->sortby($sort,$dir); $doodles = $modx->getCollection('Doodle',$c); /* iterate */ $output = ''; foreach ($doodles as $doodle) { $doodleArray = $doodle->toArray(); $output .= $dood->getChunk($tpl,$doodleArray); } return $output; ``` -------------------------------- ### Default Wayfinder Start Item Template Source: https://github.com/modxorg/docs/blob/3.x/en/extras/wayfinder/index.md The default template for the start item in Wayfinder, often used for the main menu title or a specific starting point. ```html [[+wf.linktext]][[+wf.wrapper]] ```