Search code examples
phpmodxmodx-evolutionmodx-resources

Master Snippet to control other Dynamic Snippets


I am working on a project that allows for a massive import of data into a ModX website.

With this, I am needing to be able to display the data from the fields imported, but need to be able to allow the client to place each individual field where ever they would like it to be displayed in a content resource.

So, my thoughts were to create individual snippets that would only pull individual field each.

However, I know that this would be a complete hog on the system having to query the table umpteen numbers of times, as there are potentially hundreds of fields.

How can I create a "master snippet" that will pull all fields, but I can still allow them to be used like snippets?

For instance... one pull to grab Rec1Field1, Rec1Field2, Rec1Field3, Rec1Field4, but be able to use them in a content resource like [[Rec1Field1]], [[Rec1Field2]], [[Rec1Field3]], [[Rec1Field4]]


Solution

  • Another alternative is using $modx->setPlaceholders(array('placeholder'=>'value', ...)); in your snippet, which will generate placeholders accessible anywhere in your template or nested chunks by a simple [[+placeholder]]. This would allow the user to place the tag in the content rich text or wherever he might want it, without you having to do string parsings or bother with complicated chunks.