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

    I have made a template for my news items (listed by Ditto) and am trying to show the author and date created on the page in the same why that they might appear on a Newlisting template used by Ditto. ie/ [+author+] and [+date+] - and have got as far as showing [*createdby*] and [*createdon*] but now want that to display nicely as words.

    Is there a snippet to convert say member id to member name does anyone know? (my searches in this forum hasnt thrown much up, sorry)

    Cheers

    0
      • 22815
      • 1,097 Posts
      Actually I can’t find such a snippet either, or even a how-to.

      For the username, unless there’s some secret thing not in the Document Object documentation, I figure we need to do something with getUserInfo or getWebUserInfo.

      I’m going to look at how Ditto does it and derive a snippet from that.

      I haven’t looked for a Nice Date function, but I may well need one myself sometime. What format do you wish to use?
        No, I don't know what OpenGeek's saying half the time either.
        MODx Documentation: The Wiki | My Wiki contributions | Main MODx Documentation
        Forum: Where to post threads about add-ons | Forum Rules
        Like MODx? donate (and/or share your resources)
        Like me? See my Amazon wishlist
        MODx "Most Promising CMS" - so appropriate!
        • 22815
        • 1,097 Posts
        Right. You want a username to be displayed exactly like Ditto does it.

        It turns out Ditto has a natty little function that calls the right user table etc. At first I nicked the function and put it into a snippet. It worked great, but then I realised that it was probably better all around to just reuse the function that is sat in a class on your hard drive. So I stripped the class loader from Ditto, added the two function parameters to the snippet, and then passed them to the function.

        Add this to your news item templates:
        [!UsernameLikeDitto? &createdby=$createdby!]
        


        And add this snippet called UsernameLikeDitto
        /* Snippet Name: UsernameLikeDitto
         * Short Desc: Enables use of Ditto's getcreatedby function. Requires Ditto.
         * Author: The MODx Project / Paul Gregory
         * Version: 0.1
         * Last Edited: 03-Jul-2006
         * Function: Enables use of Ditto's nice Get User Name function getcreatedby outside of Ditto.
         * 
         */
         
           // ---------------------------------------------------
          // Get Language
          // ---------------------------------------------------
        
        $language = (isset($language))? $language : "english";
        
          // ---------------------------------------------------
          // Include files
          // ---------------------------------------------------
          
        $files['language'] = "assets/snippets/ditto/lang/$language.inc.php";
        $files['functions'] = "assets/snippets/ditto/ditto.class.inc.php";
        
        foreach ($files as $filename => $filevalue) {
        	if (file_exists($filevalue) && $filename != "language") {
        	   include_once($filevalue);
        	} else if(file_exists($filevalue) &&  $filename == "language") {
        		include_once($filevalue);
        	} else if($filename == "language") {
        		return "Language file does not exist Please check: ".$filevalue;
        	  } else {
        		return $filevalue.$_lang['file_does_not_exist'];
        	}
        }
        
        if (class_exists('ditto')) {
           $ditto = new ditto();
        } else {
        	return $_lang['invalid_class'];
        }
        
        
        // ---------------------------------------------------
        // Parameters
        // --------------------------------------------------- 
        
        $createdby = isset($createdby )? $createdby : 0;
            // ID in
        
        $format = isset($format)? $format: "html";
            // cribbed from ditto function getcreatedby
        
        
        $output = $ditto->getcreatedby($createdby, $format);
        
        return $output;
        


        Please let me know if it works for you. I’ve not been able to test it on anything with multiple users but I can’t see why it won’t work.
          No, I don't know what OpenGeek's saying half the time either.
          MODx Documentation: The Wiki | My Wiki contributions | Main MODx Documentation
          Forum: Where to post threads about add-ons | Forum Rules
          Like MODx? donate (and/or share your resources)
          Like me? See my Amazon wishlist
          MODx "Most Promising CMS" - so appropriate!
          • 22815
          • 1,097 Posts
          Also see AuthorTime:
          http://modxcms.com/forums/index.php/topic,3588.msg34361.html#msg34361

          Annoyed I didn’t see that earlier.
            No, I don't know what OpenGeek's saying half the time either.
            MODx Documentation: The Wiki | My Wiki contributions | Main MODx Documentation
            Forum: Where to post threads about add-ons | Forum Rules
            Like MODx? donate (and/or share your resources)
            Like me? See my Amazon wishlist
            MODx "Most Promising CMS" - so appropriate!
            • 27
            • 117 Posts
            brilliant, works a treat.

            best regards

            0
              • 2762
              • 1,198 Posts
              Paul it’s agreat snippet! why is not in Resources Download?
                Free MODx Graphic resources and Templates www.tattoocms.it
                -----------------------------------------------------

                MODx IT  www.modx.it
                -----------------------------------------------------

                bubuna.com - Web & Multimedia Design