We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7155
    • 160 Posts
    How do I dynamically assign a TV to a document container through a snippet?
      • 16034
      • 107 Posts
      I’m not entirely sure what it is you want to do. I you by document container mean placeholder something like this (not tested):
      <?php
      $tv = $modx->getTemplateVarOutput('myTemplateVar');
      $modx->setPlaceholder('mytvplaceholder',$tv);
      ?>
      


      And then place a [+mytvplaceholder+] in your content/template. But [*myTemplateVar*] would give the same result in this case, so it’s pointless if you don’t do anything else in the snippet.

      If the above doesn’t answer your question, you need to provide som more info...
        MODx snippet-glossary 101:
        Ditto = Content Lister -- Wayfinder == Menu Builder -- Jot = Comment Control
        • 7155
        • 160 Posts
        Quote from: Kleist at Apr 17, 2009, 10:56 AM

        I’m not entirely sure what it is you want to do. I you by document container mean placeholder something like this (not tested):
        <?php
        $tv = $modx->getTemplateVarOutput('myTemplateVar');
        $modx->setPlaceholder('mytvplaceholder',$tv);
        ?>
        


        And then place a [+mytvplaceholder+] in your content/template. But [*myTemplateVar*] would give the same result in this case, so it’s pointless if you don’t do anything else in the snippet.

        If the above doesn’t answer your question, you need to provide som more info...
        I meant a document that is created in the MODx manager being made a container

        and then from within the snippet code, assigning a Template Variable to that document container.
          • 10449
          • 956 Posts
          TVs are "attached" / assigned to a specific template. If any given TV is not associated with a template, there is no way to attach it via snippet. It doesn’t really matter if that document is a container or not.

          If you meant "fill a TV with a default value", you can use the @INHERIT command, or just define a default value while creating the TV.

          To set a TV value dynamically right after a document is saved/created, you could create a plugin with a matching system event, maybe OnBeforeDocFormSave.
          Here’s a handy function you can use: http://code.google.com/p/modxresources/source/browse/branches/css_star_rating/star_rating.snippet.php?r=3
          function setTemplateVar($value, $docID, $tplVarName)
            • 3749
            • 24,544 Posts
            You can also create the TV and give it a default value of @eval $modx->runSnippet(’MySnippet’); .

            That way any value returned by MySnippet will be assigned to the TV for the current page.

            <?php
            
            // MySnippet
            
            $output = "somevalue";
            
            return $output;
            
            ?>


            In theory, you could create a TV from inside a snippet, give it a value, attach it to a template, and assign it to one or more documents but it would involve a substantial amount of direct manipulation of the MODx database. There’s almost certainly an easier way to accomplish what you’re trying to do. If you describe what you’re attempting yo do (and why), someone might be able to suggest and easier alternative that would accomplish the same goal.

            Hope this helps.
              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
              • 7155
              • 160 Posts
              Quote from: ganeshXL at Apr 17, 2009, 05:34 PM

              TVs are "attached" / assigned to a specific template. If any given TV is not associated with a template, there is no way to attach it via snippet. It doesn’t really matter if that document is a container or not.

              If you meant "fill a TV with a default value", you can use the @INHERIT command, or just define a default value while creating the TV.

              To set a TV value dynamically right after a document is saved/created, you could create a plugin with a matching system event, maybe OnBeforeDocFormSave.
              Here’s a handy function you can use: http://code.google.com/p/modxresources/source/browse/branches/css_star_rating/star_rating.snippet.php?r=3
              function setTemplateVar($value, $docID, $tplVarName)
              Ok thanks for making it clear, I got that. Thanks for the link too.

              So how do I associate(in php code) a template with a template variable?
                • 28042 ☆ A M B ☆
                • 24,524 Posts
                You can’t. Why do you want to do this?
                  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
                  • 7155
                  • 160 Posts

                  I would like to create a simple snippet to upload pdf files

                  <vent>
                  the default uploader has failed me. I did everything from permissions to URL and other paths but it has been two weeks and its the only thing left to get to work.

                  so I thought it best to program it instead of waiting for a solution. I am about to lose the client, so I think coding it in a few days would save my reputation.

                  if it cannot be done, and I find no alternative, for this project, I may have to resort to a different solution. though I WILL NOT abandon MODx. love it, esp being a programer... but its sometimes thoroughly frustrating. we will grow with it.
                  </vent>

                  Is there an existing snippet that can offer an alternative similar to a File TV that is simple and straightforward?
                    • 28042 ☆ A M B ☆
                    • 24,524 Posts
                    This is so manager users can upload .pdf files? Have you checked the manager user’s individual configurations to make sure they can upload .pdf files (or the "use system configuration" boxes are checked)?
                      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
                      • 7155
                      • 160 Posts
                      Quote from: sottwell at Apr 18, 2009, 09:51 AM

                      This is so manager users can upload .pdf files? Have you checked the manager user’s individual configurations to make sure they can upload .pdf files (or the "use system configuration" boxes are checked)?
                      yes. I have tried logged on as the admin but run into a popular error from FCKEditor. I finally posted (http://modxcms.com/forums/index.php/topic,34938.0.html) after reading through similar problems but I am yet to get a solution.

                      I wouldnt want to post in the wrong forum about this though.

                      I am wondering if it is possible to assign a file to an existing document...maybe via document ID? Maybe I can simplify my problem and have something that at least works (shrug)