We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 24624
    • 8 Posts
    I’m having a tough time learning this MODx stuff. I’m used to writing ALL of my code by hand. I simply am not seeing when to use which gadget. And why’s some stuff widgets? Those are just Template Variables, right? Are they the only kind? Couldn’t I do ANYTHING a template variable can, but with a snippet, if I wanted to take the time to write it? Or am I still just not getting it as far as what’s the difference between them...

    One thing I’d like to suggest in for documentation is a matrix table. List out template variable, snippet, widget, module, plugin, chunk across the top row. Then the first column down, list situation, function, whatever, then the standard checkmarks for where each type of gadget does apply to a situation.
      • 24624
      • 8 Posts
      As I’m reading around struggling trying to understand this stuff, I found this info from a MODx Terms post.

      Chunks are bits of text or code that can be reused throughout a site. These are primarily html but can also be javascript, css, or text. They are called within a document, snippet, TV, or template like so:

      Snippets are bits of PHP code that are used to add additional functionality to a site. These are most often used for menus but are also used for galleries, guestbooks, comments, forms, etc. They are called within a document, TV, chunk, or template like so:

      TVs are template variables and are values assigned to a particular document. They can be used to specify anything specific to the current page included a header image, sidebar items, category, author name, etc. These can be called within a document, chunk, or template


      Well, this makes it clear as mud. Any of the three can be called from any of the three. All of them seem to do almost the same thing. And it’s certainly not suggested why you would call this from that, or that from this. I’m totally lost and frustrated. I left out the parts about plugins etc because that’s redundant. Heck, they’re even called the exact same way, indicating that they are synomous with snippets. Help!
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        Template variables can be considered custom fields for document info; although they are tied to templates and are available only to documents using that templates the TV is assigned to. TVs can contain HTML and other MODx tags as Chunks can; using the @EVAL binding they can contain PHP code.

        The difference is that they are variable from page to page, while a chunk is the same across all pages that use it.

        TVs have two main display options. The Input type is what the document editor will see, while the Widget is what controls the TV’s output formatting on the final web page.

        http://www.sottwell.com/how-template-variables-work.html

        Consider snippets to be the MODx templating system’s answer to inline php code. Instead of exposing the code in <?php...?> tags in the HTML, the code is in the snippet (stored in the database) or is in external .php files included by the snippet code. Because templates, chunks and documents are stored in the database, they cannot contain inline PHP code. The snippet code is passed to the PHP eval() function as part of the document processing, since it also is taken from the database.
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          Plugins are for the back-end; instead of hacking core files to change something in the processing, there are events provided where the plugin code will be inserted (plugged in?) to modify the processing.

          Modules are also for the backend; they are additional features for Manager users; like plugins, they provide new Manager features without the need to hack the core.
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 3749
            • 24,544 Posts
            Let me take a shot here too:

            Chunks can’t contain any PHP code.

            Snippets (and plugins) most often contain nothing but PHP code.

            When you edit a document, there are predefined fields for the Title, Long Title, alias, description, etc., and the main one: Content. Template variables just give you extra, custom-designed fields (optionally with widgets to display the TV contents).

            The fields of a document, and the output of chunks and snippets are displayed with tags. The tags are replaced by the thing they refer to (e.g. a chunk tag will be replaced by the contents of the chunk, a snippet tag will be replaced with the return value of the snippet).

            The tags can be nested within other element or within other tags, so a chunk can contain a snippet tag and a snippet tag can contain a chunk tag.

            It all makes sense once it makes sense. wink

            Hope this helps.

            See also: http://bobsguides.com/MODx.html
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting