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

    I’m develloping a snippet and I need to know the id of a document other then the one where the snippet is use.

    Is there any way to get a document id base on the name of the document?

    Thanks for your help,

    Francis
    • Quote from: zipper at Mar 15, 2006, 03:23 PM

      I’m develloping a snippet and I need to know the id of a document other then the one where the snippet is use.

      Is there any way to get a document id base on the name of the document?

      Hello zipper, there are several approaches to doing what you are asking, but the best approach depends on how you are planning on using that document id. Can you explain a little more about what you are trying to accomplish in your snippet with the doc ID?
        • 33550
        • 2 Posts
        Hi Jason,

        Here my project. I just finish the interegration of Snipegallery in Modx (http://www.snipegallery.com/)

        I created a snippet that display the gallery listing, display a gallery content and a gallery image with all the navigation stuff (next, prev.., return to gallery). I also try to extend Snipegallery with stuff like random image. So here my problem... When a call the snippet from a gallery document a use $modx->documentObject[’id’] to get the id. This way the same document is use to display different level of the gallery base on different action. But, the random image is use on a other document, so $modx->documentObject[’id’] give me the current document. If I went to link this random image to be display full size in the gallery document, the snippet those not know id document of the gallery.

        What I was thinking to do is to add a parameter where you add the name of the document where stuff will be displayed.

        $gallery_document_name = "Gallery";

        I know a could also hard code the gallery document id (It’s the way it’s works now) but was thinking the document name could be cleaner. But writing down my problem here make thinking it’s not that much diffent then hard coding the document id. ;-)

        To finish, I’m trying to build a snippet that will be use in a master document but also could be use on different document but all the link genereted by the snippet go to the master document.

        Sorry for my english, I learne wathing TV....

        Best regards,

        zipper

        • One approach would be to pass a parameter to your snippet with the id to use. You might also be able to use alias, but looking the alias up can be tricky, especially if you have enabled use_alias_paths option, in which case you’d have to prepend all the alias’ of the parent documents; probably not real efficient. You could use name as well, but name would seem less permanent than the document ID and would also still require an additional query to do the lookup.