Putting Snippets In Fred Elements

hearty fare

Using Snippets

It didn't seem possible to use MODX snippets in a Fred element since all it showed was the snippet tags. That made it awkard to have, for example, lists of blog posts using pdoResources or getResources as is quite common.

From Slack:

sottwell asked...

How can you run a listing snippet like pdoResources in Fred?

The Solution:

Murray says...

You can use them as normal in an element. You just need to set "remote" to true in the option set.

What's the Story?

Fred accomodates MODX processing of MODX tags, including snippet tags like pdoResources or getResources, using an Option Set with a settiong of

  "remote": "true"

With this option set assigned to an element, you can use MODX tags as usual in that element.

  <!-- start blog list -->
<div class="container">
  <ul class="list-group">
<!-- end blog list -->

The usual chunk tpl for formatting the list items also works as expected.

  <li class="list-group-item">
  <h3><a href="[[~[[+id]]]]" class="list-group-item-action active">[[+pagetitle]]</a></h3>

What was a little confusing the first time I tried this is that in Fred editing mode as well as in Preview mode, all you'll see is the MODX tags. But once you view the page as a non-logged in visitor, you'll see the expected results.

View of snippet output