We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 14267
    • 113 Posts
    In the meantime I’ve hacked the following function into document.parser.class.inc.php:

            #  Set template variable value
            function setTV($tvname, $value, $docid="") {
    	       if($tvname== "") return false;
                   if($docid == "") $docid = $this->documentIdentifier;
                   //get id of tv
                   $result=$this->db->select("id", $this->getFullTableName("site_tmplvars"), "name = '$tvname'");
                   if (!$result) return false;
                   $row=$this->fetchRow($result);
                   $rows_affected = $this->db->update("value='$value'", $this->getFullTableName("site_tmplvar_contentvalues") , "tmplvarid=".$row['id']." AND contentid=".$docid);
                   return $rows_affected;
            }
            


    Of course if you just replace each "$this" with ’$modx’ you could put it in a snippet.
      • 29635
      • 361 Posts
      Oh my gosh I could kiss you for that! grin
      Seriously, thank you so much.
        Need MODx Ecommerce? Try FoxyCart!
        • 6726
        • 7,075 Posts
        +1

        Thanks !!!

        Quote from: The at Nov 30, 2005, 02:09 AM

        Oh my gosh I could kiss you for that! grin
        Seriously, thank you so much.
          .: COO - Commerce Guys - Community Driven Innovation :.


          MODx est l'outil id
          • 29635
          • 361 Posts
          Hi all.
          Sorry for the super long delay in this post, but that post above doesn’t quite work (at least, not from what we could figure). Luke used that as a starting point and made this, which seems to work absolutely beautifully:

          There’s a feature/bug tracking request here:
          http://modxcms.com/bugs/task/129

          // HACK **********************************************************
          // Insert this about line 1700 in document.parser.class.inc.php
          // right after function getTemplateVarOutput
          	#  Set template variable value
          	function setTV($tvname, $value, $docid="") {
          	   if($tvname== "") return false;
          		   if($docid == "") $docid = $this->documentIdentifier;
          		   //get id of tv
          		   $result=$this->db->select("id", $this->getFullTableName("site_tmplvars"), "name = '". $tvname . "'");
          		   if (!$result) return false;
          		   $row=$this->fetchRow($result);
          		   // query the db to see if there are any records to update
          		   $result=$this->db->select("Count(*) AS RecordsExist", $this->getFullTableName("site_tmplvar_contentvalues") , "tmplvarid=".$row['id']." AND contentid=".$docid);
          		   $row2=$this->fetchRow($result);
          		   if (!$row2['RecordsExist']) {
          				$fields = array(
          				"tmplvarid" => $row['id'],
          				"contentid" => $docid,
          				"value" => $value
          				);
          			   $rows_affected = $this->db->insert($fields, $this->getFullTableName("site_tmplvar_contentvalues"));
          		   } else {
          			   $rows_affected = $this->db->update("value='" . $value . "'", $this->getFullTableName("site_tmplvar_contentvalues") , "tmplvarid=".$row['id']." AND contentid=".$docid);
          		   }
          		   return $rows_affected;
          	}
          // END HACK **********************************************************
          


          We made a modified NewsPublisher snippet as well that uses this. If anybody wants to see that, just let me know. It has some stuff hardcoded, so it’s not really great for a general release, but if anybody wants to take it and run with it it shouldn’t be too hard.

          Best,
          Brett

          PS: jlarson, if your’s works, sorry! We (Luke and I) didn’t have any luck with it, but maybe it’s just because we goofed something. smiley If they both work, I guess that’s great too!
            Need MODx Ecommerce? Try FoxyCart!
            • 17665
            • 54 Posts
            Yeah, just to clarify, I had to add a check to see if the TV had any current value yet. If not, the UPDATE query doesn’t do anything so you have to do an INSERT query instead. I think MODx doesn’t create blank TV entries, but only creates them when you enter a value.

            Hope this helps someone out there.
              • 17883
              • 1,039 Posts
              Hi Luke,

              We made a modified NewsPublisher snippet as well that uses this. If anybody wants to see that, just let me know.

              I would like to see it wink

              Marc
                • 17665
                • 54 Posts
                I did this a while back so this might be an older version of newspublisher. I think it also uses a hack we did to the document.parser called setTV. I’ll have to scrounge around for that...

                Just look for stuff commented TMC.

                  • 18469
                  • 7 Posts
                  Hello,

                  please can you explain how to use this modification?

                  I’ve modified document.parser.class.inc.php file with the hack on previous page and used your modified NewsPublisher snippet but I can see no form for creating new page at all.

                  I have the newest verison of MODx (0.9.2.1).

                  I just need to create pages from front end with the possibility of uploading new image(s) (I don’t mind in which folder they will be stored) that will appear on the created page on certain place (I think this can be made with TVs).

                  Thanks for reply.

                  Martin
                    • 18469
                    • 7 Posts
                    I solved the problem of (non)appereance of the form - I wasn’t logged into manager. Now, when I’m logged, it’s ok.

                    Anyways, can you explain in more detail how to use it with TVs? I’d like to know how should the snippet call and template of the form ($formTpl) look like.

                    In the form for creating new documents I need some specific TVs such as length, width, weight, etc.
                    They can appear as textfields or textareas in the form (like in manager) and on the created page information which was entered into these textfields should appear as formatted text (between paragraph or other tags).

                    Also, it would be great if one of the TVs could be a field for uploading new image to a specific folder. This image will appear somewhere in the created document.

                    Is it possible to do this? I am not good in php so any advice or short "tutorial" highly appreciated smiley

                    Thanks
                      • 21647
                      • 9 Posts
                      hi Martin,
                      I too would love to see if the mods described earlier in this thread still appy to the latest version of Modx. If anyone has a moment to share, the ability to add TVs to newspublisher would be awesome.
                      Nmac.