ModxI have had a couple of requests lately for posts related to the uses of MODx Bindings. All of my references here are for MODx Evolution. If you are looking for resources on the topic I would suggest starting with these links:

Personally, I have not used (at) Bindings extensively in my developments thus far. I do believe that they can be a powerful tool with your MODx projects. What I am planning on doing is creating a series of posts on each of the five types of data source bindings available to all template variables:

  • @FILE file_path
  • @DOCUMENT document_id
  • @CHUNK chunk_name
  • @SELECT sql_query
  • @EVAL php_code
  • @DIRECTORY _path_to_folder

While I always try and focus on techniques and practical implications, please understand that these posts may be as representative of research on my part as actual experience (Interpretation->Please understand if I get it wrong). I will start with @EVAL.

@EVAL

@EVAL allows you to execute php code within a Template Variable (TV). The example given on the SVN:

@EVAL return "The time stamp is now ".time();

While this use is pretty straightforward where I have found I use this particular binding is to execute snippets from inside of TVs. If you have followed some of my earlier posts on creating directories I have used directory tree containers to serve as categories that can be selected via a TV. It is through the use of the @EVAL binding that this comes to fruition.

The Quill (with this example you could also use a Ditto call) call below was placed in a TV with an input type of Listbox (Single-Select).

@EVAL return $modx->runSnippet('Quill',array('parent'=>'personnel-directory','depth'=>'0'));

What this allowed me to do was to run my Quill snippet call from within my TV. My end user could then choose one of the “Categories” from the Listbox TV when the document was edited. If a new “Category” (document) was then added by the user it would be reflected as a new, additional choice within same TV. The @EVAL provides me with what I need to create a truly dynamic TV.

  • Pingback: MODX (at) Bindings, @INHERIT | Greg Smart

  • http://www.facebook.com/ronna.ogrimen Dennis-Ronna Paula Ogrimen

    Great

  • Thomas

    Hi Greg, I am using a Dropdown with a TV selecting the alias of resources to bind to and populate the TV. @SELECT pagetitle, alias FROM modx_site_content WHERE parent='235' On occasion there are resources that I desire to not have a value in this field. How does one have a resource that leaves that TV empty using a dropdown gathered with the above @Select statement? In essence an empty default. Thanks

  • http://www.gregorysmart.com Gregory Smart

    Sorry Thomas, on vacation with the family. Try the MODx forums!

  • Thomas

    Have a great vacation!

  • http://www.uggs-outlet-store.com uggs outlet

    “Well , the coach outlet view of coach handbags the passage is totally correct ,your details is really reasonable and you guy give us valuable informative post, I totally agree the standpoint of upstairs. I often surfing on this forum when I m free and I find there are so much good information we can learn in this forum!
    nike dunk