Get in touch

We've recently launched a site which has a large number (800+) of dynamic pages. It wasn't practical or necessary to create individual MODX resources for each page so the content is controlled using the awesome MIGXDB which made the creation of the database tables and the CMPs (custom manager pages) a breeze.

Linking to these pages caused a bit of a problem however and we didn't want to force our client to have to copy and paste URLs into TinyMCE so we got digging. When you use the search facility in TinyMCE MODX performs a simple search on the pagetitle or the alias. This script can easily be extended to include your dynamic pages, a list of downloads, or anything you'd want your users to link to.

The script in question is located here:


You'll see the bit we're interested in which is:

foreach ($resources as $resource) {
   echo $resource->get('pagetitle').' ('.$resource->get('id').')|'.$resource->get('id')."\n";

This loops through the matching resources and outputs the title and the ID, then a pipe (|) then the ID. All we need to do is add in our own links after this loop and they'll appear in the search results.

A crude example would be to add this after the code above:

echo 'Studio Republic|'."\n";

The script that this is returned to is expecting an integer value which it wraps in the MODX resource link tag (eg [ [ [~99] ]) so we need to adjust this script:


At line 32 you'll see this:


Which I changed to this:

} else {

This uses the function below to check if the returned value is an integer. If it is, it wraps it in the MODX link tag, if not is uses the value passed to it. Here's the isNumber function:

function isNumber (o) {
return ! isNaN (o-0) && o != null;

With all this in place, you'll now be able to select the link to our site will appear below your standard MODX resource search results. 

We added our own search function and appended the results to the list, but you could easily add both sets or results to an array, merge the two and output a single list of results. One stumbling block we came up against was that the list of links is limited to 10 results. Another hack was necessary, this time to the JQuery autocomplete function here:


At line 22 you'll see:

max: options && !options.scroll ? 10 : 150

Just increase the 10 to get more results in the list.

As with all these sort of hacks, you'll need to be careful when upgrading MODX as these files could be overwritten. Always keep a local copy and make a note of what you've changed so you can restore them if necessary.

Want to work with an agency, for good?

Call or email us today
01962 659 123

We'd love to hear from you!

A bit about you...
Confirm email
Your message
How can we get in touch?