Developer Tips

Posted by Jim Gay on Tuesday, February 17, 2009 | |

I thought I’d start writing about interesting bits about developing for Radiant that some of you might not know about.

First off, Radiant::Config:

You can see examples of the standard configuration options that Radiant uses and you’ll find an oft overlooked option page.edit.published_date?.

By setting this to true, you will have the option of changing the published date for each page when creating or editing. There’s even a wiki page about the page published_at date.

Even more interesting about it is that for developers, this is an example of how to return a boolean value from the configuration options, not just a string that is “true” or “false”.


    def value
      if key.ends_with? "?"
        read_attribute(:value) == "true"
      else
        read_attribute(:value)
      end
    end

Here’s the source

A popular extension for managing configuration options is the Settings extension. It will prevent users from seeing the values of configuration options containing the phrase “password”. While this is only a way to hide the details from typical users and not a secure way to store important passwords, it may be just enough for you. Here’s the code that does it:


module ConfigProtection
  def protected?
    key.match(/[p|P]assword/)
  end
  
  def protected_value
    if protected?
      return "********"
    else
      return value
    end
  end
end

It’s good enough for something like the Twitter extension (github)

Here are some other tips about altering the configuration options: http://wiki.radiantcms.org/Customizations_II