Nokill

by Shane Bonham | Last edited: 10/25/2016

You are probably very familiar with the default behavior of the API, where if a particular tag returns nothing, the entire "show" line will be removed. This can be super-helpful for removing content that would not make any sense without API content. For example:

getContent(
  'sermon',
  'display:detail',
  'find:' . $_GET['sermonslug'],
  'show:<h2>__title__</h2>',
  'show:<p>Date: __date format='M j, Y'__</p>',
  'show:<p>Preacher: __preacher__</p>',
  'show:<p>Series: __series__</p>'
);

If you had a sermon without a series, you wouldn't want that extra "Series:" content hanging out there all alone.

However, there are some times where it would be equally helpful, and would simplify matters greatly, if you could just let the empy API tag quietly disappear without taking everything with it. Well, now you can! It's implemented as a global API attribute:

nokill='yes'

Here's more info. Say you have this Link List call:

getContent(
  'linklist',
  'display:links',
  'find:example-list',
  'show:<a href='__url__'>',
  'show:__name__',
  'show:</a><!--__url__-->',
  'show:<p>__description__</p>'
);

Note the HTML comment after the closing link anchor tag. This is done so that if the user leaves the "URL" field blank, you won't be left with a random closing tag. However, this method is a little squirrelly, since in some browsers, a URL with double-hyphens will break the output. It would be much easier and clearner to just let the system output a link with an empty href attribute. So now you can, and it would look like this:

getContent(
  'linklist',
  'display:links',
  'find:example-list',
  'show:<a href='__url nokill='yes'__'>__name__'</a>',
  'show:<p>__description__</p>'
);

Obviously this is a very basic example, but we hope you find this increased flexibility useful.