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

    Using Wayfinder I would like to be able to assign different link texts to [+wf.linktext+] for some menu items (modx documents) so that a single document gets associated with different link texts on different pages. Please see example below (Linktext A, Linktext B, and Linktext C all point to the same document):

    www.mysite.com/index.php
    --Products
    --Linktext A
    --Service

    www.mysite.com/abc.php
    --Products
    --Linktext B
    --Service

    www.mysite.com/cde.php
    --Products
    --Linktext C
    --Service


    This selection of different link texts is part of my SEO efforts and could probably be accomplished by using a template variable (see picture below).

    However, as I am new to modx I am not sure how to integrate such a template variable into a Wayfinder call. Besides, as only some of the menu items should be associated with different link texts I am afraid a normal Wayfinder call won’t work here. Therefore, any idea on how to solve this problem is highly appreciated!

    Cheers,

    Stefan

      • 3707
      • 241 Posts
      The better solution is probably to use a custom snippet inside the Wayfinder call but you could do this with PHx.

      Add a &rowTpl template to your Wayfinder call:
      <li[+wf.id+][+wf.classes+]>
      	<a href="[+wf.link+]" title="[+wf.title+]" [+wf.attributes+]>[+wf.linktext+]</a>
      	[+wf.wrapper+]
      </li>

      and replace the [+wf.linktext+] placeholder with some PHx:
      [+phx:if=`[+wf.docid+]`:is=`44`:then=`[+phx:if=`[*id*]`:is=`11`:then=`Linktext A`:else=`[+phx:if=`[*id*]`:is=`12`:then=`Linktext B`:else=`[+phx:if=`[*id*]`:is=`13`:then=`Linktext C`+]`+]`+]`:else=`[+wf.linktext+]`+]

      Change the ID’s in the PHx code to match your document ID’s.

      if=`[+wf.docid+]`:is=`44` - this is the ID of the target document (Linktext A, B or C)
      if=`[*id*]`:is=`11` - this is the ID of the current document (index.php)
      if=`[*id*]`:is=`12` - this is the ID of the current document (abc.php)
      if=`[*id*]`:is=`13` - this is the ID of the current document (cde.php)

      Your final &rowTpl chunk should be:
      <li[+wf.id+][+wf.classes+]>
      	<a href="[+wf.link+]" title="[+wf.title+]" [+wf.attributes+]>[+phx:if=`[+wf.docid+]`:is=`44`:then=`[+phx:if=`[*id*]`:is=`11`:then=`Linktext A`:else=`[+phx:if=`[*id*]`:is=`12`:then=`Linktext B`:else=`[+phx:if=`[*id*]`:is=`13`:then=`Linktext C`+]`+]`+]`:else=`[+wf.linktext+]`+]</a>
      	[+wf.wrapper+]
      </li>

      with the ID’s changed.

      It gets quite messy if you want to change the text on lots of documents, in which case, a custom snippet would be the better option.
        • 15987
        • 786 Posts
        You could also add a Weblink to each site and have it point to the correct location.
          • 4414
          • 63 Posts
          @bob1000
          Thanks for pointing me to PHx. With your help I finally solved my problem! This is how my &rotTpl looks like now:

          Code for 2 different menu entries:

          <li>
          <a [+wf.id+] [+wf.classes+] href="[+wf.link+]" title="[+wf.title+]">
          [+phx:if=`[+wf.docid+]`:is=`55`:then=`[*drillingRig*]`:
          else=`[+phx:if=`[+wf.docid+]`:is=`56`:then=`[*oilfieldEquipment*]`+]`:else=`[+wf.linktext+]`+]</a>
          [+wf.wrapper+]
          </li>

          if=`[+wf.docid+]`:is=`55` // ID of the page "Drilling Rig"
          then=`[*drillingRig*]` // TV value set by the current document (the current page opened in the browser)
          else=`[+wf.linktext+]` // If there is no ID match use value of [+wf.linktext+] as usual

          @kylej
          Your suggestion sounds interesting, too. Could you give me a simple example of how to point a Weblink to a location?

            • 15987
            • 786 Posts
            If you create a weblink (the icon is next to the new document icon, looks like a chain link) there is a field you set called Weblink. You can either set this as a modx document id or to any url. These can then be included in your menu via wayfinder and will output the link that is in this weblink field.
              • 4414
              • 63 Posts
              Sorry, I realized the code
              <li>
              <a [+wf.id+] [+wf.classes+] href="[+wf.link+]" title="[+wf.title+]">
              [+phx:if=`[+wf.docid+]`:is=`55`:then=`[*drillingRig*]`:
              else=`[+phx:if=`[+wf.docid+]`:is=`56`:then=`[*oilfieldEquipment*]`+]`:else=`[+wf.linktext+]`+]</a>
              [+wf.wrapper+]
              </li>

              seems to work only for the first document. Is there any way to make this work for two (or more) documents? Do I have to nest the phx call?

              Looking forward to your suggestions!

              Stefan
                • 3707
                • 241 Posts
                Yeah, that won’t work because you have two else statements and the PHx isn’t nested properly.

                Here’s an easier solution using your original myLinktext TV. The TV should be assigned to any templates used by pages you want to change the link texts on (i.e. index.php, abc.php, cde.php). Then set the value of the TV for each of those pages, so you might have:

                index.php - Linktext A
                abc.php - Linktext D
                cde.php - Linktext C

                Then in your &rowTpl, use the following PHx:
                [+phx:if=`[+wf.docid+]`:is=`55`:then=`[*myLinktext*]`:else=`[+wf.linktext+]`+]

                where 55 is the ID of the document who’s text you want to change.
                  • 4414
                  • 63 Posts
                  @bob1000

                  Thanks for your explanation! Your code works for one document (55 in this case), however I would have to include at least one more document into this phx call. The problem is I don’t know how to nest two or more conditions.

                  Might the select=`options` parameter be of any help here? I was thinking about something like this:
                  [+wf.id:select=`55=[*drillingRig*]&56=[*oilfieldEquipment*]`:else=`[+wf.linktext+]`+]

                  Unfortunately, this code results in no link text at all huh

                  Do you have any idea here?
                    • 3707
                    • 241 Posts
                    If you want to change the link text on two documents, you’d have to nest PHx like this:
                    [+phx:if=`[+wf.docid+]`:is=`55`:then=`[*drillingRig*]`:else=`[+phx:if=`[+wf.docid+]`:is=`56`:then=`[*oilfieldEquipment*]`:else=`[+wf.linktext+]`+]`+]

                    The calls are nested by placing the second PHx call inside the else of the first PHx call.

                    1st PHx call:
                    [+phx:if=`[+wf.docid+]`:is=`55`:then=`[*drillingRig*]`:else=`2ND PHX CALL GOES HERE`+]

                    2nd PHx call:
                    [+phx:if=`[+wf.docid+]`:is=`56`:then=`[*oilfieldEquipment*]`:else=`[+wf.linktext+]`+]
                      • 4414
                      • 63 Posts
                      @bob1000
                      Now everything is working fine! I obviously made a mistake with a closing +] before.
                      Thank you very, very much! You not only solved my problem but also helped me to better understand the phx syntax!