We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 32241
    • 1,495 Posts
    Hi guys, I’m looking for a built in API on MODx that are able to retrieve an alias path and returned the document id.

    I found this API on MODx.
    cleanDocumentIdentifier();

    Honestly, I haven’t look into it yet, but as far as I know, it’s able to determine the document id from the alias path. Can I know the detailed of what this API will return when I put an alias as the parameter? If it couldn’t find the document, will it return something? If yes, I bet it returns the document id, is that correct?

    FYI, I’m using this for building a new plugin for MultiLingual Site. Hope it works, and I will share it later to you all.

    Thank you


    Regards,
    Wendy Novianto
      Wendy Novianto
      [font=Verdana]PT DJAMOER Technology Media
      [font=Verdana]Xituz Media
      • 18397
      • 3,250 Posts
      I am not sure of what you intend to do but note this:

      [~id~] will always output the full path to a document.

      You can get the current documents id via

       $modx->documentObject['id'];
      
        • 32241
        • 1,495 Posts
        Quote from: Mark at Dec 05, 2005, 05:58 PM

        I am not sure of what you intend to do but note this:

        [~id~] will always output the full path to a document.

        You can get the current documents id via

         $modx->documentObject['id'];
        


        I want the other way around. Instead of getting the full path from document id, I want to get a document id from a full alias path. If there is no document being associated with that full alias path, I want it to return something that I can detect, so that my code can response to it.

        Could you help me with this mark?

        Thank you

        Regards,
        Wendy Novianto
          Wendy Novianto
          [font=Verdana]PT DJAMOER Technology Media
          [font=Verdana]Xituz Media
          • 18397
          • 3,250 Posts
          How are you getting the full alias path?
            • 32241
            • 1,495 Posts
            The way the plugin run, it will read the incoming paths url, and determine whether the required document is available or not, if it’s not, it will direct the user to the default language document.

            Any other idea?
              Wendy Novianto
              [font=Verdana]PT DJAMOER Technology Media
              [font=Verdana]Xituz Media
              • 32241
              • 1,495 Posts
              After reading the document parser, I found out that the makeCleanrURL will not do anything as what I want it to be, but I found this other API getDocumentObject(), what will this thing do?

              I believe it will return a document object based on either ’alias’ or ’id’. The question is:
              1. If I choose alias method, what the alias going to be, if I use all the SEF option enabled? Is it including the path and file type or just the alias for the document. I trie with the path and it doesn’t work, but with alias it works, but the only concern is, if I have more than one document have the same alias, and they are on a different directories, which document will be returned by this API?
              2. WHat is the format for the array that was returned by this API? I can’t use print_r() in snippet, so is there any other way to output the structure of the array and store it as a string? so that I can return it through snippet?

              Thank you


              Regards,
              Wendy Novianto
                Wendy Novianto
                [font=Verdana]PT DJAMOER Technology Media
                [font=Verdana]Xituz Media
                • 18397
                • 3,250 Posts
                AFAIK you can get the current id of a document being generated from within a plugin. This would let you work based on the id which is much cleaner.

                2. You CAN use print_r($varname); in a snippet.
                  • 28042 ☆ A M B ☆
                  • 24,524 Posts
                  Yes, once you are in the Parser and plugins and such are working, the document ID is already known. You can determine the full alias from a combination of the document’s alias, and the $modx->config[’friendly_url_prefix’] and $modx->config[’friendly_url_suffix’] (aka [(friendly_url_pefix)] and [(friendly_url_suffix)] ). If you’re using friendly alias paths, that’s based on the pagetitle of the document’s ancestors (I believe...) plus the full alias.
                    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
                    • 32241
                    • 1,495 Posts
                    That’s true, but I can’t do it that way, because I want the ability to fetch a document id from other document, which is not the document where the plugin was being invoked.

                    My idea is, having a MultiLingual Plugin that are based on full SEF option provided by MODx. For example the default language is english, while the user was fetching document called home.html, and heis browser is using french, then the plugin will try to look for this home.html document on french folder, and if it’s bale to find it, it will direct the user to that page, if not, than the english language will still be displayed.

                    By having this ability, maintaining two website version/translation is not that hard, all we need to do just to make sure that the english/default language translation has the most complete list of all the documents. The other translation can be empty, which the user will still see the document in default language without sacrificing the user unable to see the page, because the other language has not been translated yet.

                    If somebody able to tell me the API for me to pass an alias path, including virtualDir, and it will then returned the right document id, or it will return null if there is no such document, it will be great. I just need the ability to check an exisiting document based on their alias path.


                    Regards,
                    Wendy Novianto
                      Wendy Novianto
                      [font=Verdana]PT DJAMOER Technology Media
                      [font=Verdana]Xituz Media
                      • 18397
                      • 3,250 Posts

                      For example the default language is english, while the user was fetching document called home.html, and heis browser is using french, then the plugin will try to look for this home.html document on french folder, and if it’s bale to find it, it will direct the user to that page, if not, than the english language will still be displayed.

                      Clever idea! FYI there are much easier ways to code what you describe.

                      You could write a plugin to listen for any of the Template Service events (choose one that fires right before a page is sent to the browser). Once that event fires it executes your code except it already knows the id of the document the visitor wants. So all you have to do is say, does the $modx->documentObject[’alias’] of this document match any alias in the language folder. Then you can redirect the visitor to the correct page.