Pixie – user editable blocks

Pixie is a simple, lightweight CMS. I had to knock something up double quick, and Pixie did the job nicely. It’s pretty light on modules and plugins, but ripe for customisation as being so lightweight it’s very easy to get into quickly.

In Pixie ‘blocks’ are small sidebar-type elements for additional comments. These are easy enough to put in for a coder, but the developers admit that easily editable block content for users is on their list to do.

Well that just won’t do will it? I need to get some user editable content in there today!

So here’s how to do it.

Create a new page in admin:

Settings > Create a new pagePage Type: Static[Create Page]

Give it a slug and Display NameDon’t give it any blocks

Set:Public: Yes

If you don’t want this content to be accessible from the menu:In Navigation: No

[Save]

Edit the content of the new page:

Publish > {your new page title}Edit page and [Update]

That’s our content ready to go. You can obviously include as much or as little as you like, but as blocks are generally sidebars it’s probably best to keep it simple and minimal.

Next we need to create a new block.This is a REALLY simple file – we leverage the Pixie static page system and hack it into a block file called admin/blocks/block_{myblock}.phpThe {myblock} name can be whatever you want – just make sure it doesn’t clash with any existing blocks. This will be the block name you add to the page you want it to appear in.

And here’s the code for your block. Simply edit $block_static to the value of the page’s slug.

You can use this method to create as many different editable blocks as you need – just change the $block_static value and the filename. You can probably adapt the same method pretty easily to use dynamic content with a bit of tweaking – I may look at that another day. I may not. Depends how far I go with Pixie.

Hmm. I know a couple of girls named Pixie. I should probably rephrase that…

[update201105251920]Later that evening I improved this slightly, so that the $block_static takes its value from the filename. This means that anyone with ftp access can very quickly and easily add a new block. Just keep a spare copy in the admin/blocks folder – possibly name it block_rename_me.php so it’s easily recognised, then site admins can copy and rename your master block_rename_me.php file to block_{newblock}.php where {newblock} is the name of the… new… block.

The changes:

Replace:

with:

You can also replace:

with:

and you now have a dynamic id you can target for styling and manipulation.

Complete with changes, with the $block_static definition moved for tidiness and consistency:

[/update]

Leave a Reply

Your e-mail address will not be published. Required fields are marked *