We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 25260
    • 156 Posts
    Hi all!

    PMS, first of all thanks for YAMS smiley

    Here is my question:

    when I try to use

    $yams->ConstructURL(NULL, $id)

    in my custom snippets (I copied the exact call), php gives me a fatal error,

    Fatal error: Call to a member function ConstructURL() on a non-object in /path/to/modx/manager/includes/document.parser.class.inc.php(770) : eval()’d code on line 64

    what am I supposed to do?

    I use last version of YAMS and MODx, I use query param mode (for the moment), I have already checked if YAMS is always first in the plugin execution order, I don’t use PHx.

    thanks in advance,

    Roberto
      • 22851
      • 805 Posts
      Hi Roberto.

      Hope you don’t mind, but I split out your post into a new thread and renamed it.

      $yams is not a global variable. ($modx is). So, to use it you have to instantiate the YAMS singleton class first. This means:

      1. Include the following at the top of the file to ensure that the yams class is defined:
      require_once( $modx->config['base_path'] . 'assets/modules/yams/class/yams.class.inc.php');


      2. Get an instance of the YAMS class using:
      $yams = YAMS::GetInstance();


      Then you can call public methods on the YAMS class, like $yams->ConstructURL(...)

      Out of interest, what are you trying to achieve here? There might be an easier way to do what you want.
        YAMS: Yet Another Multilingual Solution for MODx
        YAMS Forums | Latest: YAMS 1.1.9 | YAMS Documentation
        Please consider donating if you appreciate the time and effort spent developing and supporting YAMS.
        • 25260
        • 156 Posts
        Hi PMS,

        thanks for splitting my post. I wasn’t sure if I should post there or open a new thread smiley

        Btw, it came to my mind that I had to istantiate the yams class, but I asked here because I thought that YAMS plugin istantiated it for me, and then I was able to use it. So, it’s a simple problem smiley

        I’ve got to use it because we are in this situation.

        We built our site with 2 main templates:

        - a "folder" template;
        - a "leaf" template.

        Each document that is a container (i.e., every document in the site tree that isn’t a leaf) uses the "folder" template, it is formed by blocks, that are made with divs; each block represents a "child" page, giving a small description, a link to the page, sometimes a small static image, and rarely a links’ list of "grandchilds" made with ditto or wayfinder, or a slideshow using maxigallery.

        Each document that isn’t a folder (i.e. that is a leaf) uses the leaf template, nothing strange here.

        We studied a way to easily manage these blocks using the MODx manager: you can choose if the link to the page is above or under the description, if the image has to be on the left or on the right of the block, you can choose which percentage of the page this block has got to take, you can choose if you want a bigger or a smaller link, etc.

        This is achieved with TVs: you set them, and then the changes appears on screen.

        Here comes my snippet: it simply reads all the TVs values and builds the html for each block.
        The entire page (i.e., all the blocks) is built with ditto: my snippet is simply called by the &dittoTpl chunk.

        I use $modx->makeUrl() in my snippet to output the href in each block.

        I don’t know if this is the better way to achieve the desired result: it works and at the moment I really don’t have time to get my head again on this.

        If you have ideas, they’re really appreciated smiley
          • 22851
          • 805 Posts
          The simplest way to get your snippet to produce multilingual URLs is to make it output a YAMS placeholder: either [tt](yams_docr:docId)[/tt] or [tt](yams_doc:docId)[/tt], where [tt]docId[/tt] is the id of the document you want to link to and the docr will additionally resolve weblinks to their destination URL. Once your snippet call has generated its output YAMS will parse this like normal. That way no class instantiation etc. is required.
            YAMS: Yet Another Multilingual Solution for MODx
            YAMS Forums | Latest: YAMS 1.1.9 | YAMS Documentation
            Please consider donating if you appreciate the time and effort spent developing and supporting YAMS.
            • 22851
            • 805 Posts
            Another hint... To get the current language within your snippet call you can add a [tt]&yamsId=`(yams_id)`[/tt] parameter to it. You can also pass it other yams placeholders, like the language direction [tt](yams_dir)[/tt] and the MODx manager language name [tt](yams_mname)[/tt] that is used by snippets such as Ditto.

            Within your snippet you can use the [tt]$yamsId[/tt] variable to access language specific chunks/templates etc: [tt]’chunkname_’ . $yamsId [/tt].

            Don’t forget that you can also output yams_data placeholders too: [tt]((yams_data:docId:fieldname))[/tt].

            This works a little bit like the GetField snippet in that it allows you to output tvs from specified documents. So you could output a placeholder like so: [tt]’((yams_data:’ . $docId . ’:pagetitle_’ . $yamsId . ’))’[/tt] to get the correct language pagetitle for document [tt]$docId[/tt].

            See the YAMS placeholder documentation for more details.
              YAMS: Yet Another Multilingual Solution for MODx
              YAMS Forums | Latest: YAMS 1.1.9 | YAMS Documentation
              Please consider donating if you appreciate the time and effort spent developing and supporting YAMS.
              • 25260
              • 156 Posts
              Thanks for your reply.

              I achieved the right selection of document variables by using a snippet call, for example

              $YAMS_params = array(’get’ => ’data’, ’from’ => ’introtext’, ’docid’ => $id);
              $introtext = $modx->runSnippet(’YAMS’, $YAMS_params);

              so I don’t have to pass anything to my snippet.

              As long as I wipe out parameters from my snippet (there are a few now), I could use [[YAMS? &get=`csnippet` &from=`mySnippet`]]

              (having mySnippet_en, mySnippet_it) and get it right with my old snippet, I guess.

              Now I’m going to see which solution better fits this...

              Thanks,

              Roberto
                • 22851
                • 805 Posts
                Quote from: Roberto at Dec 16, 2009, 01:44 PM

                I achieved the right selection of document variables by using a snippet call, for example

                $YAMS_params = array(’get’ => ’data’, ’from’ => ’introtext’, ’docid’ => $id);
                $introtext = $modx->runSnippet(’YAMS’, $YAMS_params);
                That’s an excellent and simple idea. I don’t know why I hadn’t thought of doing that... Please let me know which technique you finally go for and why, since it would be good to capture this experience in the YAMS documentation.
                  YAMS: Yet Another Multilingual Solution for MODx
                  YAMS Forums | Latest: YAMS 1.1.9 | YAMS Documentation
                  Please consider donating if you appreciate the time and effort spent developing and supporting YAMS.
                  • 25260
                  • 156 Posts
                  Ok, I decided to pass &yamsId=`(yams_id)` to my snippet, since I can’t wipe out all the parameters.

                  Due to the fact that pagetitle_en and the others are TVs, I just used

                  $templateVariables = $modx->getTemplateVarOutput(array(’introtext_’.$yamsId,’pagetitle_’.$yamsId),$id,1);

                  and then, when I need it,

                  $templateVariables[’introtext_’.$yamsId];
                  $templateVariables[’pagetitle_’.$yamsId];

                  this bypasses both the YAMS and MODx parsers (at least I think so tongue).

                  I have already seen other problems, but not related to this; if I can’t figure them out, I’ll open new threads smiley

                  Cheers,

                  Roberto
                    • 22851
                    • 805 Posts
                    That’s fine. Just one warning though. Each
                    Quote from: Roberto at Dec 16, 2009, 03:10 PM

                    $templateVariables = $modx->getTemplateVarOutput(array(’introtext_’.$yamsId,’pagetitle_’.$yamsId),$id,1);
                    call will result in at least one mysql query, which can result in heavy load on the mysql server if there are lots of them. It is more efficient to use a yams_data placeholder because YAMS will consolidate all such placeholders and grab the required info from the database in a minimal number of queries.

                    (That was the reason for creating the placeholder in the firstplace. They are used internally by the YAMS Wayfinder templates and Ditto extension for efficiency.)
                      YAMS: Yet Another Multilingual Solution for MODx
                      YAMS Forums | Latest: YAMS 1.1.9 | YAMS Documentation
                      Please consider donating if you appreciate the time and effort spent developing and supporting YAMS.
                      • 25260
                      • 156 Posts
                      I do one call for each block, and every page has got <= 10 blocks, so it results in <= 10 queries for page.

                      Those calls are independent from using YAMS, I need them for the other TVs with "style" values for the blocks.

                      Do you have hints on how to minimize mysql server load? May getField can help me?