We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27444 ☆ A M B ☆
    • 117 Posts
    Hi,

    I need to pass variable parameters into the URL.

    I have created the following snippet:

    <?php
    
    $parent = $modx->documentObject['parent'];
    $id = $modx->documentObject['id'];
    
    echo'<div class="quicklinkstext">
         	<a href="www.testsite.com/index.php?id=97&category=[*pagetitle*]&carmodel=[*parent*]"><h3>Interest in this Vehicle</h3></a>
         	<p>Lorem ipsum</p>
         </div>';
    ?>
    


    And the resultant url is: www.testsite.com/index.php?id=97&category=Mazda%20Car%203&carmodel=19

    The category is getting the right parameter and even the carmodel is getting the right id of the parent.

    What I need is the url to display the pagetitle of the parent instead of its id.

    Any help would be greatly appreciated smiley
      Steven James McLean
      Tech Lead
      springbokagency.com
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      You’ll need to use a snippet (probably the getField snippet) to get the pagetitle of the current page’s parent, and use the snippet tags instead of the [*parent*] tag.
      &carmodel=[!getField? &parent=`1`!]

      will return the pagetitle (default field) of the parent.

      http://modxcms.com/extras/package/173
        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
        • 27444 ☆ A M B ☆
        • 117 Posts
        I have installed the getField as suggested.

        Could you please further elaborate how to use it in my code illustrated above because I did not understand how to use it undecided ?
          Steven James McLean
          Tech Lead
          springbokagency.com
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          You would need to download and install it (there will be install instructions when you unzip the download). Then use it like this:
          <a href="www.testsite.com/index.php?id=97&category=[*pagetitle*]&carmodel=[!getField? &parent=`1`!]"><h3>Interest in this Vehicle</h3></a>


          By default, getField will return the pagetitle of the specified document, and the &parent=`1` parameter tells it to use the current document’s parent.
            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
            • 37210
            • 131 Posts
            I love GetField o.O

            Half the time I had to create TV’s in order to display, for example, the pagetitle of the ultimate parent. It was such a hassle though because the client would then need to fill a TV for each section within the site.

            We placed a GetField call right above our side menu so that users would know what section of the website they were in. To do this we used the following call:

            [[GetField? &parent=`1` &parentLevel=`0` &field=`pagetitle` &topid=`235`]]


            GetField was also really handy in the sidemenu’s Wayfinder call. I used the call above but changed the value for the &field parameter to `id` to get the ID number of the resource. See GetField code below:

            [[GetField? &parent=`1` &parentLevel=`0` &field=`id` &topid=`235`]]


            and place this in the Wayfinder call:

            [!Wayfinder? &startId=`[[GetField? &parent=`1` &parentLevel=`0` &field=`id` &topid=`235`]]`  &outerTpl=`sidemenuOuterTpl` &innerTpl=`sidemenuInnerTpl` &rowTpl=`sidemenuRowTpl`!]


            And Ta Da! The Wayfinder call above was handy for a side menu that changes for each section a web user is in. Before we used to have to define a TV for the &startId of the side menu since it changed depending on what section of the site you were in.

            I have to say though, I have to play around sometimes with the &parent and &parentLevel parameters a bit in order to get the result I want. I go to the info at http://modxcms.com/extras/package/173 and refer to it pretty much anytime I need to use GetField.

            Hope this helps someone. I would hate to see such a useful snippet be disregarded because it may seem a little confusing to begin with!

            Sarah
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              Wayfinder will do this with its &displayStart parameter and the &startItemTpl parameter to specify the chunk tpl for its output.

              &displayStart
              default: FALSE
              values: [ TRUE | FALSE ]
              description: The displayStart parameter will cause Wayfinder to output the document used as the startId
              using the template startItemTpl. This parameter only works if the startId is not equal to zero. This
              functionality was added so that it is easy to add header to submenus.
              &startItemTpl
              default: see example
              values: name of template chunk
              description: The startItemTpl is used for templating the startId document when the parameter
              &displayStart is set to TRUE.
              available placeholders: Same as RowTpl.
              example:
              <h2>[+wf.linktext+]</h2>[+wf.wrapper+]
                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
                • 37210
                • 131 Posts
                Hi Sottwell

                Thanks for that smiley So if I set the &displayStart parameter to TRUE, the heading of the section should be displayed above the menu?

                But then how about the &startID of the Wayfinder call? Would the GetField call still be handy? Because I don’t see how the Wayfinder call automatically detects the ID of the Ultimate Parent resource.


                Sarah
                  • 28042 ☆ A M B ☆
                  • 24,524 Posts
                  Ah. Not if it’s above the startId. The displayStart only refers to the startId resource (parent), not grandparents and above that. In that case, GetField and UltimateParent would still be needed.
                    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
                    • 37210
                    • 131 Posts
                    I see, I see...I’ll keep displayStart in mind for next time anyway!

                    Thx
                    Sar
                      • 16817
                      • 1 Posts
                      Wow..Thanks for the instruction, i fixed my problem. Thanks a lot.