Zencart Plugin Framework – Day 4 – Working with templates
|Working with Zencart templates can be a real pain for store owners and even developers; especially when you install plugin that needs to display something on the store. Usually you will have to edit a template file, put a line of code to pull that plugin’s template file. What happens when you decide that you don’t want to use that plugin anymore and want to remove it? It’s not an easy task either, you will have to track down all the files you made changes to revert them back to previous stage, which can be years ago (and sometimes it’s not even you who installed the plugin in the first place, which further complicates things).
In our years of working with Zencart, we have seen so many people struggled to install a simple plugin. All Zencart store owners seem to have to take a crash course in PHP, HTML and Zencart structure in general. But do they have to? Is it really necessary for them to do so? The answer, in our opinion, is a big NO. What’s so beautiful about WordPress is that almost 99% of its plugins are just plug-and-play, so simple, so straight forward, so effort less. It’s not very do-able with the current Zencart’s structure which is lacking lots of “hooks” for 3rd party modules to plugin in, but we try to make that happens, at least within the template.
Our Zencart Plugin Framework(ZePLUF) was designed with the end users in mind, and by end users we do mean real store owners with zero to nil PHP or Zencart’s internal structure knowledge. ZePLUF introduces what has been the norm in most modern framework: the “hooks” inside. the views (templates). In ZePLUF, these are called “holders” because they are basically place holders which can be input with any display text. A carefully thought out and coded template should already contain all these place holders in the appropriate position which the store owners when installing a new module can decide to use those pre-placed “holders” to render a certain view from the plugin. Obviously, the store owner can also easily place a new “holder” if he or she wants.
There are 2 ways to place a holder into a template file:
Option 1 (PHP code)
Slot name can be any thing you want, but it will act as a unique identifier for the plugins and other codes to input the content into it
Option 2 (HTML code)
Alternatively, it’s also possible to simply put a simple HTML code as shown above and let ZePLUF parse it for you. You will have to change the configuration of riCore to turn the “parse_holders” to true, however.