On March 26, 2019 we launched new MODX Forums. Please join us at the new MODX Community Forums.
Subscribe: RSS
  • I am trying to use the Static Files feature for a Template Variable (General Information tab, select Media Source for Static File, then select static file).

    Anybody know where there is any documentation on how MODx uses static files for TVs? (The note on the form says only, "An external file location where the element source is stored.")

    There's no mention of Static Files in the docs page for TVs: https://rtfm.modx.com/revolution/2.x/making-sites-with-modx/customizing-content/template-variables/creating-a-template-variable (last updated Jan 20, 2014).

    There are a few lines on Static Elements here https://rtfm.modx.com/revolution/2.x/administering-your-site/upgrading-modx/upgrading-to-2.2.x#Upgradingto2.2.x-StaticElements but it doesn't mention TVs.

    There may be other info but the docs search doesn't return anything (https://forums.modx.com/thread/99534/modx-docs-issues-particularly-with-search).

    What I need to know, for example, is,
    • How is the TV's Static File (intended to be) implemented?
    • Is the file content used only as the default TV content, or otherwise?
    • Does the TV require to use any specific Input or Output Type?
    • Any other requirements for use?

    I have been experiencing sporadic behaviours which may be due to me not implementing In/Output types properly, or caching issues. Sometimes the updated content of the static file appears front-end, sometimes it doesn't, even after repeated cache-clearance.

    Any info/advice welcome!
    • It's quiet out there .. smiley
      • I tried creating a fairly complex static TV and I can tell you that its file contains nothing but the default value of the TV. The files for static elements are meant to hold only the 'content' of the element (e.g., the text of a chunks and templates, and the code of a snippets or plugins).

        Given that only the default value of the TV is saved, there's usually no point in having a TV be a static element unless its default value is a fair amount of text.

        I don't think the static nature of your TVs is the problem. More likely it's a nesting/cache issue. For example, if your TV tag is inside a snippet tag that's inside a chunk and the chunk tag is in a template or another chunk, MODX can have trouble with it since the TV tag may not be parsed at the point that it's used.

        Also, if the TV tag is unparsed (with a !), that delays its processing so that its value may not be available when the tag it's in is parsed.

        Feel free to post a TV tag that your having trouble with.
          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
        • Well, I've no idea whether it's a problem with the TV, or caching. The content in question was the standard Twitter timeline widget, downloaded from the twitter site. Originally the twitter code was placed in the TV by the site user, and worked ok. Then I noticed that it was extending beyond the div that was supposed to constrain it. I removed the widget code, replaced with some text and it worked ok, so the TV seemed fine. I replaced the widget code and the this time the page wouldn't save; just displayed an endlessly looping status bar.

          Then I tried placing the widget code into the default field of the TV. Nothing showed. Normal text showed ok.

          That's when I decided to try a static file for the TV, with the widget code. Nothing.

          Than I spent a while trying out alternatives to the widget, namely the TwitterX and JSONDerulo extras. They did show up in the front end after placing them in the static file. I tried them in the TV default field, but nothing.

          Over time, as I was styling the extras code, the TV sporadically failed. I eventually stopped trying to use any twitter code, using only text to figure out how the static file and default content are supposed to work. Eventually the default content wouldn't show at all, whether static or not.

          Running out of ideas, I decided to upgrade - to 2.4.3. That went smoothly. Tried the TV again with text and the default value still does not show up at the front end. It is in the database, and it saves in the TV default text field. It just doesn't do anything.

          The original twitter widget still won't allow the page to save when placed in the page TV field. The extras cose works ok. But now I want to use it as the default content to keep it away from users.

          BTW I've cleared the cache a million times, both vis modx manager and the entire cache dir contents in Plesk.

          Stumped.
          • When a TV won't save with code in it, the problem is almost always the host's mod_security settings (which could well have changed while you were working on this).

            Rather than using a TV with a snippet tag in the default value, could you just use a snippet tag and hide the snippet from the users? TVs are meant to hold resource-specific values and they are quite slow and inefficient compared to alternate methods, especially when you're using the default value.

            You could also put the snippet tag in the page Template and hide the Template from users.

            Another possibility is to create a new System Setting, put the snippet tag in it, and put a Setting tag on the page where you want the output:
            [[++SettingName]]


            though just using a snippet tag directly would be faster.
              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
            • I manage my own dedicated server now, so there (should be) no server-side settings changed.

              I wasn't using a snippet tag in the TV default field, but several lines of html and javascript, as supplied by twitter:
              <a class="twitter-timeline" href="https://twitter.com/userName" data-widget-id="7586611599999999">
                Tweets by @userName
              </a>
              <script>
              !function(d,s,id){
                var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';
                if(!d.getElementById(id)){
                  js=d.createElement(s);
                  js.id=id;
                  js.src=p+"://platform.twitter.com/widgets.js";
                  fjs.parentNode.insertBefore(js,fjs);
                }
              }
              (document,"script","twitter-wjs");
              </script>
              (formatted for clarity)

              I could put the snippet in the template, but the front-end space is supposed to be for the user to edit as they please. Having the code as default means it doesn't get lost or accidentally damaged by the user. It also means the TV input type can be rich text (which tends to wrap tags around code like the above), so they can add other content when they need.

              At the moment I have the TV as:
              Input Type: Textarea
              Default Value: "Test default TV content."
              Output Type: default
              Allow Blank: Yes

              If I delete the TV content in the page and save, the space on the site empties. No default content. I searched the page source code and it's not just hidden somewhere. It is saved in the database. Just not being compiled into the page code.

              Same behaviour on 2.3.5 and now 2.4.3. Could this be a bug? Is there anything else that will affect TV default values? My feeling is it's not the script, but something in modx which is being tripped too easily.
              • I've put JS into the caption of a TV, but I've never tried putting it in the default_text field. Offhand, I can't think of any reason it wouldn't work, though the usual method is to put it in a chunk (hiding the chunk from users if necessary).

                I have a couple of thoughts about why it isn't working, though neither is all that likely.

                1. The @ sign in your code makes MODX think it's an @ binding TV. (Easy to test -- just remove the @ sign and see if the code shows up in the source).

                2. The page you're viewing has a value in the TV field for that TV. The default value is only used if there is no record at all for that resource in the modx_site_tmplvar_contentvalues table. If you find a record in that table where the contentid is the ID of the resource and the tmplvarid is the ID of the TV, that's your problem.

                BTW, #2 means that if a user changes the TV value while editing any page, the default value will never show up again on that page (unless you hide the TV from the user).
                  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