We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7111
    • 30 Posts
    I’m using modX to run a local newspaper’s website, and everything works really well. There are just a few things that I’d like to hear a few opinions on.

    Like I said it’s a newspaper website and I have tried to emulate the look of the paper as much as possible. The layout for the front page stories is the area of concern for me. The paper can have many different layout possibilities. Such as, you could have a story with 3 mugs, or a graph, or it could contain an image with a cutline, or it could be a single pull quote from the story itself. I’m using ditto to output the front page stories of that week’s issue from a specific folder to the index page of the website. The ditto call works great and does what I want it to. The issue I’m having concerns with is the chunk I made that ditto uses to render the stories.

    I’m using template variables to hold a specific image, or pull quote, or mug image that is associated with a particular story. Like I said, I’m using a chunk for ditto to use to output front page stories. I’m also using phx to use some logic within the chunk. The chunk contains the following code:

    <h1><a href="[~[+id+]~]" title="[+longtitle+]">[+pagetitle+]</a></h1>
    
    [+phx:if=`[+subhead+]`:isnot=``:then=`<h2>[+subhead+]</h2>`:else=` `+]
    
    [+phx:if=`[+Graph-image+]`:isnot=``:then=`<p class="graph"><a href="[~[+id+]~]" title="[+longtitle+]">[+Graph-image+]</a></p>`:else=` `+][+phx:if=`[+Graph-datasource+]`:isnot=``:then=`<p class="data-source">[+Graph-datasource+]</p>`:else=` `+]
    
    [+phx:if=`[+Photo+]`:isnot=``:then=`<p class="mug-photo"><a href="[~[+id+]~]" title="[+longtitle+]">[+Photo+]</a></p>`:else=` `+][+phx:if=`[+Photo+]`:isnot=``:then=`<p class="cutline">[+cutline+]</p>`:else=` `+]
    
    [+phx:if=`[+Mug3+]`:isnot=``:then=`<div class="mug">`:else=` `+][+phx:if=`[+Mug3+]`:isnot=``:then=`<p>[+Mug3+]</p>`:else=` `+][+phx:if=`[+Mug-caption3+]`:isnot=``:then=`<p class="mug-caption">[+Mug-caption3+]</p>`:else=` `+][+phx:if=`[+Mug3+]`:isnot=``:then=`</div>`:else=` `+]
    
    [+phx:if=`[+Mug2+]`:isnot=``:then=`<div class="mug">`:else=` `+][+phx:if=`[+Mug2+]`:isnot=``:then=`<p>[+Mug2+]</p>`:else=` `+][+phx:if=`[+Mug-caption2+]`:isnot=``:then=`<p class="mug-caption">[+Mug-caption2+]</p>`:else=` `+][+phx:if=`[+Mug2+]`:isnot=``:then=`</div>`:else=` `+]
    
    [+phx:if=`[+Mug+]`:isnot=``:then=`<div class="mug">`:else=` `+][+phx:if=`[+Mug+]`:isnot=``:then=`<p>[+Mug+]</p>`:else=` `+][+phx:if=`[+Mug-caption+]`:isnot=``:then=`<p class="mug-caption">[+Mug-caption+]</p>`:else=` `+][+phx:if=`[+Mug+]`:isnot=``:then=`</div>`:else=` `+]
    
    [+phx:if=`[+pullquote+]`:isnot=``:then=`<div class="pullquote">`:else=` `+][+phx:if=`[+pullquote+]`:isnot=``:then=`<p class="pullquote-text">[+pullquote+]</p>`:else=` `+][+phx:if=`[+pullquote+]`:isnot=``:then=`<p class="pullquote-whosaid">[+pullquote-whosaid+]</p>`:else=` `+][+phx:if=`[+pullquote+]`:isnot=``:then=`<p class="pullquote-whoarethey">[+pullquote-whoarethey+]</p>`:else=` `+][+phx:if=`[+pullquote+]`:isnot=``:then=`</div>`:else=` `+]
    
    <p>[+summary+]</p>
    <p class="more-story"><a href="[~[+id+]~]" title="Read the full article...">Read full story...</a></p>


    i put some line breaks in there so you could see a little better as to what I’m trying to accomplish. The logic is something like, If a story contains an image or cutline, output it, if a story contains one or more mugs output the mugs and associated mug captions, otherwise, don’t output anything.. And so on. The same logic applies to graphs or pull quotes, what have you.

    The problem is, sometimes a story will contain an image with a cutline and a pullquote and a mug. I could not use all four template variables, because the chunk above is meant to display just an introduction to the story with a single image and cutline or two or three mugs with mug captions. But if I have to use an image, cutline and pull quote in the story, the chunk above will output both the image, cutline and the pullquote in the front page summary.

    I guess what I need to know is, how can I make it so that the ditto chunk above will only output one of the desired template variables in the summary?

    Do I just need to redesign the whole logic of how this works? It seems so overly complicated, or am I just making that way? I’d love to hear how a more accomplished modX’er would have accomplished the above.

    Sorry about the long post, it’s just one of those problems that’s so hard to summarize. ;-)

    Thanks!
      • 7111
      • 30 Posts
      Well, I didn’t think people would need to see more than the main page as that is where the issues lie, but here ya go... ;-)

      username: demo / pass: demouser Sorry, had to close account, no freebies. ;-)

      Also, the phx isn’t inside a snippet, it’s inside a chunk. This chunk (frontpagesummary) is being called by ditto...

      [[Ditto?&parents=`71` &extenders=`summary` &seeThruUnpub=`1` &depth=`2` &hidePrivate=`0` &trunc=`1` &truncLen=`400` &tpl=`frontpagesummary` &sortBy=`menuindex` &sortDir=`ASC` &display=`all`]]
        • 21257 MODX Staff
        • 730 Posts
        derekm,
        This is Ditto 2?
          Mike Schell
          Lead Developer, MODX Cloud
          Email: [email protected]
          GitHub: https://github.com/netProphET/
          Twitter: @mkschell
          • 21257 MODX Staff
          • 730 Posts
          I’m not saying that I have an answer, but maybe this could be done with a different approach.

          1) If you were to think about it in terms of having separate chunks for each possible version of the front page summary, chunks which contain no phx logic to show/hide things, how few could you reduce it to?

          2) If you were to look at the variables (placeholders) Graph-image, Graph-datasource, Photo, Mug3, Mug-caption3, Mug2, Mug-caption2, Mug, Mug-caption, pullquote, and try to arrive at the simplest possible logic that would drive the decision to choose between the chunk/templates from the question above, what would it be?

          If the answers to these questions start getting as voluminous as the phx logic already in your chunk, then it’s probably not a helpful shift in perspective. But if there is more simplicity to it, then it might be as easy as creating a snippet to drive the template choice. It would take some messing about - I get vertigo sometimes trying to visualize where the recursive parsing of the MODx core, Ditto and PHx all combined will work as expected and where it won’t.

          nP
            Mike Schell
            Lead Developer, MODX Cloud
            Email: [email protected]
            GitHub: https://github.com/netProphET/
            Twitter: @mkschell
            • 7231
            • 4,205 Posts
            It seems that and elseif would be handy in PHx. Maybe you could build a custom modifier for PHx which could do this logic for you. There are some interesting examples of custom modifiers here:
            http://wiki.modxcms.com/index.php/PHx/CustomModifiers
              [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&#39;t know what it is.
              Do you, Mr. Jones? - [bob dylan]
              • 11975
              • 2,542 Posts
              Hi,

              AFAIK PHx supports elseif statement:

              Ex=> [+phx:if=`[*xx*]`:is=``:then=`result1`:else:if=`[*xx*]`:is=`something else`:then=`result2`+]

              :-)
                Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
                • 7111
                • 30 Posts

                derekm,
                This is Ditto 2?
                It’s the latest Ditto BETA release I believe.


                I’m not saying that I have an answer, but maybe this could be done with a different approach.

                1) If you were to think about it in terms of having separate chunks for each possible version of the front page summary, chunks which contain no phx logic to show/hide things, how few could you reduce it to?

                2) If you were to look at the variables (placeholders) Graph-image, Graph-datasource, Photo, Mug3, Mug-caption3, Mug2, Mug-caption2, Mug, Mug-caption, pullquote, and try to arrive at the simplest possible logic that would drive the decision to choose between the chunk/templates from the question above, what would it be?

                If the answers to these questions start getting as voluminous as the phx logic already in your chunk, then it’s probably not a helpful shift in perspective. But if there is more simplicity to it, then it might be as creating a snippet to drive the template choice. It would take some messing about - I get vertigo sometimes trying to visualize where the recursive parsing of the MODx core, Ditto and PHx all combined will work as expected and where it won’t.
                To answer question 1, I could reduce it to 6 different chunks I think. As to question 2, I think putting all possible combinations in seperate chunks would be the most efficient as well as less confusing, but I’m not sure how to make ditto call a specific chunk depending on the template variables that a story contains. Any ideas?


                @derekm: I basically just wanted to see if you’re using additional or bigger images in the full article.
                Nope, same size. They are sized manually. The bigger version of the images, if they are considered important enough, are uploaded to the gallery. I’m working on using phpthumb to resize images dynamically, just not high on my priority list right now.


                It seems that and elseif would be handy in PHx. Maybe you could build a custom modifier for PHx which could do this logic for you. There are some interesting examples of custom modifiers here:
                http://wiki.modxcms.com/index.php/PHx/CustomModifiers
                I agree, an elseif would be handy. I didnt know about the ability to add my own custom modifier to phx, this helps tremendously, the only fallback is that the phx code is already so confusing to work with, it will be an effort to integrate into my existing code. Of course I can’t actually say that until I dive in. ;-)


                [+phx:if=`[*xx*]`:is=``:then=`result1`:else:if=`[*xx*]`:is=`something else`:then=`result2`+]
                Like I said above, that’s some confusing syntax, but I’ll see what I can come up with. smiley

                Thanks, everyone for your replies. I’ll see what I can work out when I get home tonight. I’m working at the paper today, as I also do their layout for the "analog" version. smiley

                Thanks!
                  • 3749
                  • 24,544 Posts
                  I’ll second the suggestion of making this a snippet rather than a chunk and using php to set up the alternatives. You could still use chunks for some of the content but use php to decide which chunks get into the finished page.

                  The key would be to create complete pseudocode that describes exactly what you want to do. Once that exists, the php code should be pretty easy to knock out.

                  Bob
                    Did I help you? Buy me a beer
                    Get my Book: MODX:The Official Guide
                    MODX info for everyone: http://bobsguides.com/modx.html
                    My MODX Extras
                    Bob's Guides is now hosted at A2 MODX Hosting
                    • 21257 MODX Staff
                    • 730 Posts
                    Quote from: derekm at Nov 27, 2007, 12:53 PM

                    To answer question 1, I could reduce it to 6 different chunks I think. As to question 2, I think putting all possible combinations in seperate chunks would be the most efficient as well as less confusing, but I’m not sure how to make ditto call a specific chunk depending on the template variables that a story contains. Any ideas?

                    Just an idea, which should work as long as the recursion elves mind their own business.. (which they won’t of course tongue)

                    If you used a chunk (not a chunk name) in your Ditto call..
                    [[Ditto? &tpl=`{{frontpagefigure-outer}}` ... ]]
                    


                    Then crafted a call to a custom snippet inside that chunk..
                    Chunk: frontpagefigure-outer ::
                    [[FrontPageDecision? &Graph-image=`[+Graph-image+]` &Graph-datasource=`[+Graph-datasource+]` &Photo=`[+Photo+]` &Mug3=`[+Mug3+]` &Mug-caption3=`[+Mug-caption3+]` &Mug2=`[+Mug2+]` &Mug-caption2=`[+Mug-caption2+]` &Mug=`[+Mug+]` &Mug-caption=`[+Mug-caption+]` &pullquote=`[+pullquote+]` ]]
                    


                    (You want to make sure the chunk isn’t crafted in such a way that an extra line break or whitespace will be added around the snippet call.)
                    Then your snippet FrontPageDecision could do the rest..
                    <?php
                    
                    $chunkToReturn = '';
                    // the following logic is bogus - just means to show how you can now access the articles tvs in php to craft the logic
                    if( $Graph-image != '' && $Mug2 == '' ) {
                        $chunkToReturn = 'chunk1';
                    } elseif( $Graph-image == '' && $pullquote != '' ) {
                        $chunkToReturn = 'chunk1';
                    }
                    
                    return $chunkToReturn;
                    


                    So PHP decides the name of the chunk to return back into the frontpagefigure-outer chunk, which in return sends it back to the Ditto call.

                    Will this work? I can’t say. It might - it would probably take some trial and error tweaking, and having someone more familiar with Ditto than I am wouldn’t hurt. The first problem you might run into is passing that chunk to the Ditto call - it may not work because PHx might "steal" it from the MODx parser before it does what it’s supposed to do. There are ways to get around that.

                    Hope I’m not wasting your time with this hare-brained scheme.
                      Mike Schell
                      Lead Developer, MODX Cloud
                      Email: [email protected]
                      GitHub: https://github.com/netProphET/
                      Twitter: @mkschell
                      • 7111
                      • 30 Posts
                      Ah, I had no idea you could even do that! I’ll give it a shot and report back if I encounter any issues. Thanks,
                      netProphET.