We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 43621
    • 40 Posts
    The title says it all,
    how is it possible to display a kind of "default content" if there is no article listed at the overview page?

    Articles 1.7.8
    Revo 2.3.1

    Thx in advance!
      • 44580
      • 189 Posts
      Not sure why you would want to do this but why not just create a placeholder article with the "default content" of "Coming soon..." or whatever you want to say. Then just un-publish it once you have real content.
        • 43621
        • 40 Posts
        I want this to work automatically.

        The idea behind is, to create articles which are displayed only fridays (special offers). The rest of the week there should be a placeholder.

        It seems I need a DB-call which counts the "published" articles and if there are 0 published, it has to display the placeholder, but possibly there is a predefined functionality for that?

        [e] Ok I've solved that problem with a snippet, which checks the current time with the general publication day (Friday). As long as the current daytime is "Friday" the [[+article]] placeholder is called, otherwise the [[$placeholder]] chunk is called. The articles have the same publishing date so they should be displayed as soon as the snippet calls the [[+article]]. Works fine for now. smiley

        I call that snippet in the Article-Container-Template Textfield.

        If there is a better solution, tell me! smiley
        [ed. note: diluvian last edited this post 9 years, 6 months ago.]
          • 3749
          • 24,544 Posts
          I'm not sure what you're doing, since placeholders aren't really "called". Feel free to post the code of the snippet if you want advice on it.
            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
            • 43621
            • 40 Posts
            Ok here we go. With the "SpecialOffer" snippet I can decide when the articles in general are displayed (wheter or not there is any article created) and when the placeholderChunk is displayed. The publish date of the articles which have to be displayed on "Friday" (I define that with &opening=`Friday`) should be set to this day, too otherwise there will be displayed nothing.

            Articles Template-Tab:
            [[SpecialOffer? &placeholder=`[[$myPlaceHolderChunk]]` &opening=`Friday`]]


            My SpecialOffer Snippet:
            if(time() > strtotime("this $opening 0:00") && time() < strtotime("this $opening 23:59:59"))
            {
            	echo "[[+articles]]";
            }
            else
            {
             	 echo $placeholder;
            }


            MyPlaceholderChunk:
            Some Placeholder HTML Code... ;)
              • 3749
              • 24,544 Posts
              Returning the value you want to display instead of using print or echo is standard in MODX snippets, so this might be better in the long run:

              if(time() > strtotime("this $opening 0:00") && time() < strtotime("this $opening 23:59:59")) {
                  $output =  "[[+articles]]";
              } else {
                   $output = $placeholder;
              }
              return $output;


              If you don't mind terse code, you could do it a little faster like this:

              return (time() > strtotime("this $opening 0:00")) && (time() < strtotime("this $opening 23:59:59"))? "[[+articles]]" : $placeholder;


              You might also consider replacing the articles placeholder with it's actual value if you can (maybe using $modx->getPlaceholder()). It might save a parsing pass and it would be probably be more reliable with respect to caching.
                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
                • 43621
                • 40 Posts
                Thanks for the corrections. I've now done it like that:

                return (time() > strtotime("this $opening 0:00")) && (time() < strtotime("this $opening 23:59:59"))? $modx->getPlaceholder('articles') : $modx->getChunk($placeholder);


                I used getChunk, too and hope this was the right step smiley.
                  • 3749
                  • 24,544 Posts
                  It looks great. Using getChunk() should save a little time as well. smiley

                  It would also be wise to make sure that the code that sets the 'articles' placeholder doesn't execute unless it's going to be displayed. You might be able to do that by moving the code into the snippet and using $modx->runSnippet() inside an if() statement.
                    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