MODx Evolution: Creating a Simple Custom Snippet Part 4 – Optimize with Caching

Part 0: Introduction
Part 1: Write and Test the PHP Script
Part 2: Create the Snippet
Part 3 – MODx API, Placeholders, Chunks

In the fourth part of this brief series on creating a custom MODx Evolution snippet, we’re going to do some optimizing to make our snippet a little more efficient.  So far the snippet seems to be working as expected and is pulling in the feeds as needed.  However, it’s a little inefficient.  The way things are set up now, every time someone refreshes the page, the script fetches a new copy of the rss feed from the coding pad, or whatever source you’re pulling your feeds from. If you have a heavily trafficked site where people spend a lot of time on your site and visit many pages (thus, for example, constantly refreshing your snippet call in the sidebar), this can be resource heavy on both your side slowing your website down, and also on the web server that you’re pulling the feeds from.  We can mitigate this by implementing caching.

Continue reading “MODx Evolution: Creating a Simple Custom Snippet Part 4 – Optimize with Caching”

MODx Evolution: Creating a Simple Custom Snippet Part 3 – MODx API, Placeholders, Chunks

Part 0: Introduction
Part 1: Write and Test the PHP Script
Part 2: Create the Snippet

So far we have created the raw PHP script and tested the code outside of MODx.  We’ve started the process of transforming this script into the rssfeedFetcher snippet and we have it working on the Learn MODx website.  We’ve learned how to add optional parameters with default values to our call and everything seems to be working as expected. At the close of the last segment, I mentioned that our snippet is still relatively inflexible because the user has no control over how the output looks.  We’re going to rectify this today by tapping a little into the MODx API to create placeholders and utilize chunks to allow for some templating and customization of the output.

Continue reading “MODx Evolution: Creating a Simple Custom Snippet Part 3 – MODx API, Placeholders, Chunks”

MODx Evolution: Creating a Simple Custom Snippet Part 2 – Create the Snippet

Part 0: Introduction
Part 1: Write and Test the PHP Script

In the last installment of this brief series we went through the process of creating the raw PHP script that will form the basis of our snippet. We tested the code outside of MODx and it seemed to work pretty well. In this part, we’re going to start the process of transforming this script into a MODx snippet.  As I said before, I will be working on the Learn MODx website that we built during the MODx Beginner series of tutorials.  My goal is to use the snippet to add one or maybe two sections of MODx related feeds to the sidebar of the website.  But first, we need to create the snippet itself, so let’s get to work 🙂

Continue reading “MODx Evolution: Creating a Simple Custom Snippet Part 2 – Create the Snippet”

MODx Evolution: Creating a Simple Custom Snippet Part 1 – Write and Test the PHP Script

Part 0: Introduction

In the introductory post, I explained briefly what we’re going to create, made some important disclaimers, and blew some hot air around.  In this part, we’re going to get our hands dirty by diving in and writing the PHP script and testing it outside of MODx to make sure it works. In general, I think this is a good idea because it allows you to iron out any purely PHP issues in your code before dealing with the MODx side of things. Chances are that even after you’ve tested it and ported it into MODx, you’ll end up adding more PHP logic and stuff but if you can test most of it outside MODx first, it should potentially save you some headaches and debugging time when working inside MODx.  This is especially important because once inside the MODx editor there’s no syntax highlighting, automatic indenting and all that other good stuff.

With that in mind, let’s go ahead and create our script.

Continue reading “MODx Evolution: Creating a Simple Custom Snippet Part 1 – Write and Test the PHP Script”

MODx Evolution: Creating a Simple Custom Snippet Part 0 – Introduction

Welcome to this new series of tutorials on the MODx CMS where we’re going to be talking about creating custom snippets for MODx Evolution 1.0.x.  We’ve been building a website called Learn MODx and so far it’s just a simple but functional website.  We’re going to keep building on and enhancing this website.  Before we proceed, I should mention that I’ve already updated the Learn MODx website to the most recent version of MODx Evolution 1.0.2.  If you started at the beginning with me and still have your site running on 0.9.6.3, please take a moment to upgrade your site.  You can watch this screencast on how to upgrade your MODx site.

In this series on creating simple custom snippets, we’re going to look at the basics of creating your own snippets.  I’m no PHP guru so we’re not going to be doing anything crazy here 🙂 but I hope to give you enough information to jump start you into exploring and digging further to create bigger and better things and see how truly powerful and extensible MODx is.  At this point I assume you know what a snippet is and have probably already used some snippets in your own MODx websites.  (If you don’t know what a snippet is, please go over the MODx Beginner Series as that will help lay the foundation for this series).

Continue reading “MODx Evolution: Creating a Simple Custom Snippet Part 0 – Introduction”