plainblack.com
Username Password
search
Bookmark and Share
Subscribe

How to get the most out of Snippets

Snippets 

Snippets are probably one of the most useful assets in WebGUI, but you need to know how and where to use them.

Whereas most assets have templates - snippets don't - they are what they are.  Snippets don't have to be large either - they can be as simple as one character.  And they're cached in WebGUI so they're pretty fast to work with.
Snippets are also versioned - so any changes you make to them won't be made until it has been committed.

Because of this simplicity, it's easy to overlook how useful they really are.

Let me suggest a few examples of places where I use snippets:

Snippets in Style Templates

I have multiple styles for different roots, each with their own navigation, but with many common elements.  Because of this I use snippets to store those common elements and use assetproxy calls to link them in.  This means each style itself is really only made up of half a dozen assetproxy calls.

ie.

 ^AssetProxy(header);
 ^AssetProxy(css);
 ^AssetProxy(javascript);
 ^AssetProxy(body);
 ^AssetProxy(navigation);
 ^AssetProxy(body2);
 ^AssetProxy(footer);
 

And the navigation portion changes for each one.

It's relatively easy to do as you build one page, then split it up into the sections you want into separate snippets.  This makes it incredibly easy to reuse snippets in different objects.

Variables

Snippets can be used as variables in your site as well.  Because they're versioned and can be as simple as one character they take naturally to this.

For my own site I have pages where I refer to major versions of our software (like 8,9,10, etc) and minor versions (.01, .02, etc).  Every time our software updates I have to update all of the download links to our software accordingly.  If it's a minor version then it's pretty simple, but if it's a major version update then all of our release notes and documentation needs to reflect the new major version.

To help manage this, I use snippets as variables to hold the current major and minor versions - and then on every page that refers to a particular version I AssetProxy in those variables.

So if I have a link to a file I might have something like:

<a href="/releasenotes/releasenote^AssetProxy(majorversion);^AssetProxy(minorversion);.pdf">Latest Release Note</a>

So if my major version is 12 and minor version is .02 then when the assetproxies are expanded this becomes "/releasenotes/releasenote12.02.pdf" 

This means that all I need to do to update our versions is upload all of the files associated with a release and change one variable on our website.

We can then check all the links are working correctly and when we're happy we commit the change. 

This is just one way you can use snippets as variables - there are so many different ways you could use this though - so the world is your snippet!

Now.. it is worth mentioning that this does slow down your site a bit (how much I honestly have never measured), but instead of grabbing a single style and page, it's then doing multiple assetproxy calls to grab other pages.  Since this is in your style template, it's happening several times for every page.

Snippets are cached in webgui - so it should be a pretty quick action to assetproxy them in, but if you're dealing with a large website that's getting a large number of hits - then this is something you'll want to think about.

For the site I set up, dynamic updating is far more important than speed - so we honestly don't care, but YMMV :)

Keywords: howto javascript snippet style themes

Search | Most Popular | Recent Changes | Wiki Home
© 2017 Plain Black Corporation | All Rights Reserved