We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27726
    • 1 Posts
    Kudos to everyone! Amazing secrets have been exposed here. Keep up guys and thank you for sharing...
      • 6228
      • 249 Posts
      Revolution 2.0.5

      Need MODx API access from outside the framework?

      <?php
      define('MODX_API_MODE', true);
      include_once '/path/to/webroot/index.php';
      
      ... your code here ...


      Boy it doesn’t get any easier than that.
        lo9on.com

        MODx Evolution/Revolution | Remote Desktop Training | Development
        • 30585
        • 833 Posts
        Need to show your hate for IE6?

        Here’s my way of doing it:

        A tiny javascript on page load
        <!--[if lt IE 7]>
        <script type="text/javascript">	
         $(function() { 
           var $box = $(".alertbox"),
              stateCookieName = 'alertbox_state',
              alreadyClosed = $.cookie(stateCookieName);
        
          // The box should already be hidden initially (using CSS preferrably).
          // If not, uncomment the line below:
           $box.hide();
        
          // Show the box if it hasn't already been closed.
          if (alreadyClosed != 1) {
            $box.delay(900).fadeIn(900);
          }
        
          $box.find('.close').click(function() {
            $box.fadeOut("slow");
            $.cookie(stateCookieName, 1);
          });
        });
        </script>
        <![endif]--> 
        


        The XHTML
            <div class="alertbox">
              <span class="message">You are using an unsafe and outdated browser. For a better experience on our site, please upgrade to FireFox, Google Chrome or Internet Explorer 9. These new browsers are free and run much faster!</span>
              <div class="bloc_navigateurs"> 
                <a href="http://www.mozilla.com/products/download.html?product=firefox-3.6.13&os=win&lang=en-US" target="_blank"><img src="includes/themes/default/images/icons/misc/Firefox-16.gif" width="16" height="16" alt="Firefox" /></a>
                <a href="http://www.google.com/chrome/intl/en/landing_chrome.html?hl=en" target="_blank"><img src="includes/themes/default/images/icons/misc/Chrome-16.gif" width="16" height="16" alt="Chrome" /></a>
                <a href="http://windows.microsoft.com/ie9" target="_blank"><img src="includes/themes/default/images/icons/misc/IE-16.gif" width="16" height="16" alt="Internet Explorer " /></a>
              </div>
              <span class="close">close</span>
            </div>


        Obviously you should hide your alertbox div using CSS by default or isolate it with IE conditional comments so it only affects EI6.
        This solution relies on Jquery and the Jquery Cookie plugin.

        With some CSS creativity, you can get the box design that fits you best.

        As you can see, this solution only warns the user once. The cookie takes care of not annoying them anymore once they click on the close button.

        Some people have different ways of doing this and this works just fine for me.
        Last but not least, you need your own icons and you can suggest whatever browser you like. No disrespect to Safari and Opera, convenience sided with the three I recommended.
          A MODx Fanatic
        • I use getResources alot in Revo.
          Wrote a tutorial for it:
          http://modxtutorials.com/using-the-power-of-the-modx-getresources-add-on.html
            MODX Ambassador (NL) | Responsive web design specialist, developer & speaker
            DESIGNfromWITHIN, MPThemes and Any Screen Size
            Follow me on Twitter | Read my blog | My code on GitHub
            • 21122
            • 153 Posts
            Some excellent tips in this thread! Feel like I’ve learned a whole bunch of stuff in just 10 minutes!

            Anyway, this might be something that you all do anyway, but I like to maintain a header file that I can just copy and paste into MODx when I start a new site, complete with tags.

            Something like the following:

            <!DOCTYPE html>
            <html>
            <head>
            <base href="[[!++site_url]]" />
            <title>[[++site_name]] | [[*longtitle]]</title>
            <meta http-equiv="Content-Type" content="text/html; charset=[[++modx_charset]]" />
            <meta name="description" content="[[*description]]" />
            
            <link href="assets/css/styles.css" rel="stylesheet" type="text/css" media="screen" />
            <link href="assets/css/reset.css" rel="stylesheet" type="text/css" media="screen" />
            <link href="assets/css/print.css" rel="stylesheet" type="text/css" media="print" />
            <link rel="shortcut icon" type="image/ico" href="/assets/images/favicon.ico">
            
            <!--[if IE 7]>
            
            <![endif]-->
            
            <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
            <script type="text/javascript">
            
            $(document).ready(function() {
            
            });
            
            </script>
            
            </head>
            
            


            This way, when it gets passed over to the client, they can easily add to the title and description of the page when they are adding a new resource. All very helpful for SEO!
            The template also has links to the same file structure I use (CSS), a link to the jQuery library and a document.ready function, ready for any plugins that I use.
            • Jquery 1.4.2? Still? Joking aside, http://code.jquery.com/jquery-latest.min.js might be a better choice (unless one of your scripts requires a given version, in which case you’re better off storing it locally in case they stop linking it)
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org
                • 21122
                • 153 Posts
                Fair point Susan! Although I did think I was quote up to date with 1.4.2.

                I’ll go amend my template.
                  • 15446
                  • 1 Posts
                  interesting thread to read!
                    • 29955
                    • 9 Posts
                    I like to greet users according to the time of day, i.e. morning, afternoon and evening. To do this I use the following snippet.

                    <?php
                    $current_time = date(G); // Gets the current hour of the day, e.g. 6, 17 etc.
                    $greeting[0] = "Good morning "; // Use an array to hold the greetings
                    $greeting[1] = "Good afternoon ";
                    $greeting[2] = "Good evening ";

                    if ($current_time >= 0 && $current_time < 12) {$output = $greeting[0];} // Display greeting (morning)
                    if ($current_time >= 12 && $current_time < 18) {$output = $greeting[1];} // Display greeting (afternoon)
                    if ($current_time >= 18 && $current_time < 24) {$output = $greeting[2];} // Display greeting (evening)

                    return $output; // Display the final result
                    ?>

                    I combine this with the user’s name using the following snippet:

                    <?php
                    $currentUser = ucwords($modx->getLoginUserName()); // Get username and capitalize the first letter
                    if ($modx->userLoggedIn()) {$output = $currentUser;} else {$output = "Anonymous";}; // Display user’s name if logged in, else display "Anonymous"

                    return $output; // Display the final result
                    ?>

                    The end result when included in a template would be something like: "Good morning John Doe", or "Good afternoon Anonymous". I just think that it’s a nice touch and a bit more personal! If anyone has any suggestions on improving this, I’d appreciate it. I am a PHP and Revolution novice (busy teaching myself).
                      • 27672
                      • 168 Posts
                      I like to greet users according to the time of day, i.e. morning, afternoon and evening. To do this I use the following snippet.

                      that’s a good idea, just be aware that times generated by php are going to be based on whatever the server time is. if most of your users are within the same timezone, or within a couple zones this really won’t matter. just be aware that if people are on the opposite side of the world it’ll be backwards to them.