We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18206
    • 59 Posts
    Hello,
    I’m working on a customized front-end for adding news to a website by combining (and hacking) FDM and Ditto.
    Ditto has so far been the reliable, comforting father in this my first contact with CMSes, but I’ve come to a dead end. I have modded FDM to not publish the news documents by default, but want to handle this through the same front-end page, meaning Ditto needs to show the unpublished documents but only for moderators/admins.

    Preferably, I would like to have the option of using a custom template (chunk) for the unpublished news in order to style them differently from the rest. Is there anything similar to what I’m requesting or do I have to don my plumed coding headdress?
      • 30884
      • 142 Posts
      Ah, now. I had a similar problem, there was something you need to do to allow ditto* to list unpublished pages, I wound up making a series of direct php & modx dbapi calls to check the status of a page and ’temporarily’ allowing the logged in person to view the un-published page. It is possible but it’s probably not the easiest way to do it.

      The modx dbapi routine checked the status of a page (published or un-published) and I had the snippet format the placeholder differently in the tpl for the ditto item to show ’un-publish’ for published and ’publish’ for non-published articles.

      Let me have a look through the code here and I’ll post what I can at some point.
      Cheers

      TxRx

      *Make sure your using latest ditto version, there’s been revisions/fixes in the way to allow published and un-published docs to be listed.

        p i x e l p u s h e r e x t r o d i n a i r e
        A x i s A n i m a t i o n . c o m
        • 7231
        • 4,205 Posts
        Use PHx in the ditto tpl with an if/else statement based on the published value. You can simply change the style info, or you can change the entire output. I think you can even use PHx to load one chunk if published and another if not, need to test this to see if the ditto placeholders are parsed (I have never tested it this way, but I bet it works).

        There is info on PHx in the wiki and it is installed as part of Ditto to use within the Ditto Tpl chunks and it is on by default, so it is ready to go.
          [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

          Something is happening here, but you don't know what it is.
          Do you, Mr. Jones? - [bob dylan]
          • 30884
          • 142 Posts
          Ah now, see, I’ve not played with PHx. I suspect I will be after reading your explanation laugh
            p i x e l p u s h e r e x t r o d i n a i r e
            A x i s A n i m a t i o n . c o m
            • 25663 MODX Staff
            • 12,272 Posts
            What I’d probably do is to be a bit lazy and just use CSS and the document object. Doing it cleanly would require using a bit of PHx to conditionally add the css in your template.

            You should be able to set your class on your items in your template to something like the following:
            class="mystyle[*published*]"


            That way the actual output would be either mystyle0 or mystyle1 and there’s your alternating selectors based on published status. Of course the DocObj code is probably wrong but that should be simple enough to figure out (doing this from memory, early).
              Ryan Thrash, MODX Co-Founder
              Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
              • 18206
              • 59 Posts
              That was fast, thanks a bunch guys! smiley
              For the template part, I’ve decided to go with the CSS solution by using the [+published+] placeholder as rthrash mentioned above. It doesn’t look so fancy in the resulting plaintext perhaps, but it’s a simple, foolproof solution and it should be the most efficient solution performance wise.

              Now I only need to figure out how only allow a logged in publisher to see the unpublished documents.
                • 7231
                • 4,205 Posts
                Now I only need to figure out how only allow a logged in publisher to see the unpublished documents.
                Use a snippet (I think personalize will do this) to display one ditto call if logged in as publisher and another if not.
                  [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

                  Something is happening here, but you don't know what it is.
                  Do you, Mr. Jones? - [bob dylan]
                  • 30884
                  • 142 Posts
                  I’m going to have a closer look into half of this little lot. Seems that things have progressed quite a bit whilst I’ve been away from working in Modx laugh
                    p i x e l p u s h e r e x t r o d i n a i r e
                    A x i s A n i m a t i o n . c o m
                    • 18206
                    • 59 Posts
                    The hat went on; I basically read Personalize and hacked it to my own needs.. not sure if it’s safe.

                    This is my conditional test
                    isset ($_SESSION['mgrValidated'])


                    It seems to return 1 when I’m logged on and NULL when I’m not.. is it safe to use or should I go with an API function instead? (couldn’t find a good one)