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
How are you getting the full alias path?
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?
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
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.
-
☆ 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.
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