On one condition

| Discussion

I had some time to kill, so like any ExpressionEngine developer would do I grabbed the EE source code and spent some time digging through it. What I found is something super secret nobody is supposed to know about. Luckily for you I am very bad at keeping secrets, so here goes.

In the Template parser there is this little feature that is available when processing advanced conditionals. Usually when you want to check if a member belongs to a certain group, you would do something like:

{if logged_in_member_group == 1}
  // Show something super secret only VIP member are allowed to see.
{/if}

This is fine if you only need to check for one member_group, but as soon as you have multiple, things get crazy. You end up with a bunch of {if}'s and {else}'s or writing a custom plugin if you want to keep your template somewhat simple. But the folk over at EllisLab have added something to the template parser that they've kept quiet... a special conditional solely for doing this exact thing.

This is the little piece of code that can make a huge difference in keeping your template code clean:

// /system/expressionengine/libraries/Template.php (line 3030)
// Member Group FALSE function, Super Secret!  Shhhhh!		
if (preg_match_all("/in_group\(([^\)]+)\)/", $str, $matches))
{
  $groups = (is_array($this->EE->session->userdata['group_id'])) ? $this->EE->session->userdata['group_id'] : array($this->EE->session->userdata['group_id']);

  for($i=0, $s=count($matches[0]); $i < $s; ++$i)
  {
    $check = explode('|', str_replace(array('"', "'"), '', $matches[1][$i]));

    $str = str_replace($matches[0][$i], (count(array_intersect($check, $groups)) > 0) ? 'TRUE' : 'FALSE', $str);
  }
}

What this basically allows you to do is the following:

{if in_group('1|7|8')}
	<p><q>You shall not p... oh, you passed.</q></p>
{/if}

As you can see this cuts down on template code considerably, but what intrigues me the most is the syntax. I've never even seen anything like this. Not in native add-ons or third-party add-ons, so where did it come from and when was this added?

A new year is upon us

| Discussion

2011 is right at our doorsteps and promises to bring even more exciting times for us all. Even if 2010 was already a great year.

For me, this last year marked the beginning of my career as an EE add-on developer and I've been getting pretty good feedback so far.

Add-ons like Auto Expire, BW Required Category, Remember Me and Timetravel have done so much for me even though they're released for free. Karma points are severely underrated.

For the new year I have some big plans and I hope there is enough time to execute them all. So far all if my add-ons have been released for free, but that is (hopefully) going to change soon. I'll still be releasing add-ons for free, but a select few (new) add-ons will be released commercially.

Apart from all of my online activities 2011 will be even more exciting for me on a personal level. After 2 long years of renovating, I'll finally move into my apartment in a great part of Rotterdam called 'Blijdorp', which pretty much translates to 'Happyville'. With a name like that, what more could I wish for?

Rapid content entry in ExpressionEngine 2

| Discussion

Today I made an amazing discovery about a nice little feature hidden in the depths of the ExpressionEngine 2 control panel. The ability to create a bookmarklet for rapid content entry.

You can find this magic feature on your 'My account' page in the control panel under 'Channel settings > Bookmarklet'.

My account > Channel settings > Bookmarklet

You can create a bookmarklet here that will basically take any content you have selected in your browser (on any site) and populate the publish form with that content. Obviously it is limited to one field, so you will have to specify which one, but still... it's pretty awesome.

Creating a bookmarklet

Select the default field

Bookmarklet created

Just save the generated bookmarklet as a bookmark and you'll be able to rapidly add any content to your site without the hassle of going through the entire publish menu and all.

This would be a pretty neat addition to a Tumblr style blog to quickly add content to your journal by creating several bookmarklets for different kinds of content. To set up a Tumblr-like blog, have a look at How to Build a Simple Tumblr Blog with ExpressionEngine by Andy Johnson or Lee Reamsnyder's How I Built a Tumblr-style Blog With ExpressionEngine.

Just play around with it and you'll see how easy it actually is.

BW Category Count

| Discussion

While doing some community service in the ExpressionEngine forums, I came across a thread where someone was looking for a way to display categories on a single entry page. The title was a bit misleading, but basically he was looking for a way to show or hide a piece of HTML depending on the number of categories assigned. So I made a quick extension that would make this a lot easier.

So without further ado, I present to you BW Category Count.

BW Category Count is an amazingly simple extension for ExpressionEngine 2.x that does only one thing... it adds a {category_count} variable to the exp:channel:entries loop. As you've already guessed, the category_count variable holds the number of categories assigned to an entry. This is great for showing/hiding pieces of code surrounding your {categories} loop as it is also available in conditionals. Let's give you a quick example.

{exp:channel:entries channel='blog'}
  {if category_count == 0}
    No categories assigned to this post.
  {if:else}
    {categories backspace='1'}
      <a href="{path='blog'}">{category_name}</a>, 
    {/categories}
  {/if}
{/exp:channel:entries}

BW Category Count only has 1 optional parameter: show_group. The show_group parameter allows you to only count a category if it is in a specific category group, much like how the show_group parameter on the categories-loop works.

{category_count show_group='1'}
{category_count show_group='1|3|4'}
{category_count show_group='not 2'}
{category_count show_group='not 2|3'}

So as you can see it as fits right in with the native tags.

This add-on will only be released for ExpressionEngine 2.x as there already is a similiar add-on called Entry Category Count made by Erik Reagan for EE 1.x.

If you do happen to stumble upon a bug (though higly unlikely because it is amazingly simple) please let me know either on Twitter or on the support forum on Devot:ee.

It is time to get my geek on

| Discussion

It can be called a miracle that I've survived this long without a place to vent my thoughts and opinions, but no longer!

It's been a long time coming, a very, very long time, but in the end it was worth it: my personal site is live! This will be my own little corner of the web where I can geek around and talk about things I care about. This will mainly be on topics like frontend development, ExpressionEngine or other webdevelopment related stuff. But aside from that, I will talk about day to day stuff that keeps me busy.

As you might have noticed there are some parts of the site aren't finished yet, but who cares about add-on documentation or a selection of my work? I sure as hell don't. But eventually they will come and this is just an attempt to force myself to speed it up a bit as I'm a lazy bum.

One last thing: I am no designer and I know that all to well. So I asked a good friend of mine, Marcelo Vélez, to help out a bit with the design. I showed him a few examples of what I liked and he came up with the general concept. I worked from there to create the rest of the site. So a big shout out to my buddy!