Skip to content
This repository

In this tutorial, you’ll learn how to create a nice “hello world” Typo textfilter plugin. It will just make a Javascript pop up appear at load time saying “Hello world”.

First, create a plugin using Rails default plugin generator

$ ./script/generate plugin typo_textfilter_helloworld

Load your plugin in your favourite text editor, and start with init.rb. You’ll need to load the Typo Textfilter Plugin API and your Helloworld class

require 'text_filter_plugin'
require 'typo_textfilter_helloworld'

Now, edit your lib/typo_textfilter_helloworld.rb, this is where the big thing start

First, declare your Helloworld class :

class Typo
  class Textfilter
    class Helloworld < TextFilterPlugin::MacroPost
      plugin_display_name "Hello world"
      plugin_description "Adds a hello world pop up"

Now, add the method with the help text for your macro

def self.help_text
  %{
You can use `<typo:helloworld>` to have a stupid javascript pop up saying "hello world" }
end

Now, create your macro filter which does all the work:

def self.macrofilter(blog,content,attrib,params,text="")
  %{<script type="text/javascript">alert('hello world');</script>}
end

Close the unclosed classes and methods

    end
  end
end

In your code, you can call your hello world macro filter :

<typo:helloworld />
Something went wrong with that request. Please try again.