We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3071
    • 99 Posts
    Oh, I got the ideas alright, just not the expertise to execute them!
      • 6511
      • 60 Posts
      danny_kay1710 Reply #72, 16 years ago
      Does anybody know if onParseDocument the template variables have been populated from the page?

      $tv = $modx->getTemplateVar('keywords');
          $array = explode(",", $tv);
          
          print_r($array);


      The above just isn’t working and I don’t know why. I want to grab keywords from a keywords template variable instead of using a array but it just seems to ignore it completely and come back with an empty array.

      Anyone with any ideas please? huh It’s driving me insane!
        • 3071
        • 99 Posts
        Hey it works a treat! You’re a genius! How can we hook this up to some kind of back end thing so we don’t have to edit the raw code? I assume that would be module or something. Also, can we specify that out of a list, let’s say I specify 10 keywords and 10 URLs to hyperlink them to, can we say, stop after you’ve done 3 per document? So if a certain document doesn’t happen to feature the second keyword is would move on to the next until it foinds one that is there, up to a limit of 3? I believe this is array territory!

        Your latest question, of course, I have no idea about. Would be good to specify all keywords for the complete website, all URLs that we want to point them at and also a limit of 3 per page (as an example)

        Maybe i can send you a good curry recipe? laugh
          • 6511
          • 60 Posts
          danny_kay1710 Reply #74, 16 years ago
          Maybe wink

          I am only starting to understand the modx API (and it taking a little to get my head round) so backend stuff may take me considerably longer than this has!!!

          It’s just some quick code and I am sure it could probably be done more elegantly but it does the job and that’s the main thing.

          A quick stop would be allow you to modify the $keywords variable in a template variable rather than raw code but as you can see from above I am having difficulty.
            • 27708 MODX Staff
            • 2,502 Posts
            In all likelihood it is order of execution. From what I understand TVs are merged into the content output at or after the onParseDocument event and you’ll need to call the plugin at a later event for this to work. If you are working in Evolutioon (which I recall you are) you can see the order of execution here: http://wiki.modxcms.com/index.php/Order_of_execution (this is the old user wiki and main contain inaccuracies.)

              Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. Blog ✦ Twitter ✦ LinkedIn ✦ GitHub
              • 6511
              • 60 Posts
              danny_kay1710 Reply #76, 16 years ago
              I am working in Revolution, I am not sure what benchesters is running but I assume it is Revo since everything I have coded is working.

              How applicable is the link to Revo?
                • 6511
                • 60 Posts
                danny_kay1710 Reply #77, 16 years ago
                I have changed the plugin to fire on onWebPagePreRender instead of onParseDocument and it appears to have sped the page loading up with it on now
                  • 18913
                  • 654 Posts
                  Set up a template variable of type textarea (I named it "relinklist"), add your substitution list into the default options area, select widget type delimited text (with the delimiter set to ",") and assign it to the templates you are using.

                  I linked the plugin to the "OnParseDocument" but there may be a better event to use (since it seems to get called a couple of times, in my test case).

                  Anyway, then change the code to deal with the TV like this :
                      //$keywords = "list of keywords was here";
                  
                  $keywords = $modx->getTemplateVarOutput(array("relinklist"),$docid='[~id~]',$published=1);  //MattC
                  echo $keywords['relinklist'];  //MattC inserted for debugging
                  
                      $array = explode(",", $keywords['relinklist'] );  //MattC
                  


                  Hope this helps,
                  MattC

                  EDIT : Note this is for Evo ...
                    • 3071
                    • 99 Posts
                    I am actually using the older modx 9.063 but was testing on Evo as well! If that confuses anyone at all! To cut a long story short, the most recent tests are on the older version at it is working fine.
                      • 6511
                      • 60 Posts
                      danny_kay1710 Reply #80, 16 years ago
                      That code doesn’t seem to work on Revolution.

                      It looks like the order of execution may have changed between versions.