We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 5173
    • 12 Posts
    Nevermind, I think I answered my own question through trial and error.

    <?php
    $output = '
    	<div style="border: 5px solid #49535c; padding: 0px; margin-bottom: 8px; margin-left: 5px; width: 92%; text-align: center; background-color: #fffce6;">
    		You currently have <a href="[~[+alias:subscription+]~]">no subscription</a> active.
    	</div>';
    return $output;
    ?>


    That seems to work!
      • 5173
      • 12 Posts
      Damn - I spoke too soon.

      Although it does appear to work is the aliaslink is just in text that will be rendered in the browser, it doesn’t work if the PHP code is executed directly as in:

      <?php
      header("Location: [~[+alias:events+]~]");
      ?>


      So, I’m still looking for a way to map an alias to a doc URL or at least an ID...
        • 22303 MODX Staff
        • 10,725 Posts
        In snippets, simply do:
        <?php
        return '<a href="' . $modx->makeUrl($modx->documentListing['subscription']) . '">no subscription</a>';
        ?>

        This has nothing to do with AliasLinks. That’s part of the core.

        Then, you can customize AliasLinks to work however you want; all it does is set placeholders that use $modx->documentListing to get the id from the full alias (which includes the path, i.e. $modx->documentListing[’blog/article-1’] if you have friendly alias paths enabled).

        Here’s an alternate version that uses a slightly different placeholder format to avoid conflicts with phX:
        <?php
        if (!empty($modx->documentListing)) {
            foreach ($modx->documentListing as $linkAlias => $linkDocId) {
                $modx->setPlaceholder("~{$linkAlias}", "{$linkDocId}");
            }
        }
        ?>

        Just register that code in a plugin OnWebPageInit, and you can then use it in content like:
        <p>
        <a href="[~[+~parentalias/alias+]~]">some link I'm creating</a>
        <a href="[~[+~anotheralias+]~]">another link I'm creating</a>
        </p>
          • 5173
          • 12 Posts
          Thanks for the tips OpenGeek. FWIW, it appears that your plugin will work anywhere as long as the final code is passed through the documetn parser. So this will work in most cases:

          <?php
          return '<a href="[~[+alias:subscription+]~]">no subscription</a>';
          ?>


          However, if that doesn’t then this will work:

          <?php
          header("Location: ".$modx->makeUrl(0, 'subscription', '', 'full'));
          ?>


          Hopefully I’ve got all my bases covered. Thanks again to everyone that contributed. (This was my first time posting here in the forums and I have to say the response time and volume of relevant replies was amazing and unexpected. Kudos to all that lurk here smiley )
            • 22303 MODX Staff
            • 10,725 Posts
            Quote from: chrisbloom7 at Feb 16, 2009, 09:18 PM

            Thanks for the tips OpenGeek. FWIW, it appears that your plugin will work anywhere as long as the final code is passed through the documetn parser.
            Exactly, that’s what placeholders are, though they are also available via API directly (e.g. $modx->getPlaceholder()).

            Quote from: chrisbloom7 at Feb 16, 2009, 09:18 PM

            <?php
            header("Location: ".$modx->makeUrl(0, 'subscription', '', 'full'));
            ?>

            This is actually incorrect and though it may produce the result you want, that will not work in future releases of MODx. The way I showed in the previous example using $modx->documentListing is the proper way. $modx->makeUrl() should always be used with the document id, and the second parameter is now deprecated (and is reused for other purposes in the upcoming MODx 2.0).
              • 5173
              • 12 Posts
              Quote from: OpenGeek at Feb 16, 2009, 09:23 PM

              This is actually incorrect and though it may produce the result you want, that will not work in future releases of MODx. The way I showed in the previous example using $modx->documentListing is the proper way. $modx->makeUrl() should always be used with the document id, and the second parameter is now deprecated (and is reused for other purposes in the upcoming MODx 2.0).

              GREAT to know! Thanks again!