Go to content Go to navigation Go to search

Conditional RJS

Conditional RJS is difficult to understand for a newbie, but it starts making sense when you start thinking abour it.

First of all RJS is not Javascript. RJS is Ruby code that gets translated into Javascript. Take for example the following code:

if @delivery_locations.blank?
    page[:previous_delivery_locations].remove if page[:previous_deliver_locations]
else
  if page[:previous_deliver_locations]
    page[:previous_delivery_locations].replace_html @delivery_locations
  else
    page.insert_html :top, 'delivery_details', @delivery_locations
end

It all makes perfect sense. Hang on. How can Ruby check if an element is on a page if page[:previous_delivery_locations] if it's server-side, not client-side? Again, Ruby only generates Javascript which then gets executed client-side. What we want in this case is something along the lines:

if @company_delivery_locations.blank?
  page << "if ( $('previous_delivery_locations') ) {"
    page[:previous_delivery_locations].remove
  page << "}"
else
  page << "if ( $('previous_delivery_locations') ) {"
    page[:previous_delivery_locations].replace_html @delivery_locations
  page << "}else{"
    page.insert_html :top, 'delivery_details', @delivery_locations
  page << "}"
end

Notice the page <<. Everything that follows is raw Javascript and gets inserted exactly as we write it. That's more like it!

Remember, if you aren't sure about your RJS, always check the generated source through your best friend Firebug (or well, just View Source), and double check if it's what you hoped for.

If you want to read more on the subject, take a look here: Conditional RJS Explained.

glz_custom_fields 1.1 released

A new version of glz_custom_fields has been released. Not all features on the roadmap made it in, but these did:

For glz_custom_field & if_glz_custom_field to look into custom fields above 10 on single articles, you will need to apply the following patch: publish_r2777.patch (490.00B) . If you are familiar with SVN, all you have to do is run the following command in the textpattern directory:

patch -p1 -i path/to/publish_r2777.php publish.php

For the ones that aren’t familiar with SVN, replace getCustomFields() with the following.

The above patch is for the publish.php that comes with the latest stable TXP, 4.0.6. An upgrade is strongly recommended.

The post starting the glz_custom_fields forum thread was updated accordingly.

I would like to thank everyone that has supported this plugin, all you guys are great!

Comment [8]

glz_custom_fields unveiled

It's official, glz_custom_fields has been launched. For the ones that have no idea what I'm talking about here, take a look at drop down lists for custom fields on Textpattern Forum. For the ones that do know and would like to see the plugin in action, glz_custom_fields_unveiled.mov (10.33MB). A few screenshots while you're waiting for the screencast to download:

glz_custom_fields under Extensions tab glz_custom_fields editing a custom field glz_custom_fields creating a new article glz_custom_fields saving a new article

As you might know from the forum, this plugin is for grabs for £10 (or $20, or €10). It's a big (1,5k lines of code big), complex plugin that took me a few months to develop.

Since my original post back in December 2005 - 10 more custom fields please - a fellow TXP user, Randy, asked me to make a private plugin which was using the unlimited, pimped custom fields concept. 3 months later, after having finished the plugin for Randy and realizing that putting the hack in a plugin was possible, here we are, the custom fields plugin happening.

The £10 will get you updates for life and unleash the true potential of your favourite blogging tool.

After donating, you will be taken straight to a copy of glz_custom fields v1.2.3. Let's rock!

Comment [24]

  << Older posts ...