We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 29076
    • 615 Posts
    Hope some of you great coders can help me with this (simple, I guess) question:

    In my pagetitles I have for example: Betula nana L. ssp. tundrarum (Perfil.) Á.Löve & D.Löve. Another example: Bistorta vivipara (L.)S.F. Gray.

    What I need is a snippet that returns the two first words in the pagetitle and put an underscore _ between them, like this:

    Betula_nana or Bistorta_vivipara.


    Can someone please help me making a snippet like this?


    Thanks.
      I think, thererfor I am! But what I am, and why...?
      • 27889
      • 415 Posts
      Try this:
      <?php
      $t =explode (' ',$modx->documentObject['pagetitle']);
      echo $t[0].'_'.$t[1];
      ?>
        MODx Sites & Prestations: http://dp-site.fr [Last MODx Site]
        MODx Repository: [HOME] [MetaTagsExtra] / Current Dev: [xFDM]
        • 29076
        • 615 Posts
        Thank you very much for the answer. Unfortunately it did not work. I tried it in a call like this:
        <img src="assets/images/species/[!get-name!]_close.jpg" width="172px" height="170px" />

        where my snippet get-name contain your code, but it did not work.
          I think, thererfor I am! But what I am, and why...?
          • 27376
          • 576 Posts
          Quote from: Sylvaticus at Jun 08, 2007, 06:17 PM

          Thank you very much for the answer. Unfortunately it did not work. I tried it in a call like this:
          <img src="assets/images/species/[!get-name!]_close.jpg" width="172px" height="170px" />

          where my snippet get-name contain your code, but it did not work.
          What does the final output of the page look like? Is there anything in your "System Events" log (Reports -> System Events)?

          Try changing the [tt]echo[/tt] line to [tt]return[/tt] (shouldn’t make a difference, but worth a try). Add some sort of static text to the return value (like ’test’ for instance) to see and make sure the snippet is being executed correctly.
            • 29076
            • 615 Posts
            First I tried return instead of echo, but it didn’t work. Than I tried
            <?php
            $t =explode (' ',$modx->documentObject['pagetitle']);
            echo 'Betula'.'_'.'nana';
            ?>


            and the snippet returned what it was suppose to do.

            Nothing in my System events.
              I think, thererfor I am! But what I am, and why...?
              • 27889
              • 415 Posts
              Check the source of the html document to see if something is echoed and what.
              Are you sure that ’pagetitle’ is the correct field and contains your words ?
              Where do you call the snippet, from the same document id which you want retrieve the words ?
                MODx Sites & Prestations: http://dp-site.fr [Last MODx Site]
                MODx Repository: [HOME] [MetaTagsExtra] / Current Dev: [xFDM]
                • 29076
                • 615 Posts
                Thanks again. It was just a typo. Everything works great now. laugh
                  I think, thererfor I am! But what I am, and why...?