0

The question says a 1000 words but what I basically want to do is build a Locomotive CMS plugin and I am stuck at the basics. Which is not such a good thing.

I have followed the instructions of this gem because it's the only piece of reference I could find: https://github.com/colibri-software/locomotive_plugins

I've added locomotive_plugins to my gemfile. I made a file called locomotive_test_plugin.rb and placed it in my lib folder (I found this a logical place to put this file because it doesn't say clearly in the gem instructions). I did add the lib folder to the config.autoload_paths in the application.rb. And I kind of hoped that it would work

The locomotive_test_plugin.rb looks like

class LocomotiveTestPlugin
  include Locomotive::Plugin

  def initialize_plugin
    # Custom initialization code
  end

  def to_liquid
    {:test => "test"}
  end
end

LocomotivePlugins::register_plugin(LocomotiveTestPlugin, "test_plugin")

Turns out it didn't. I also made a custom gem called locomotive_test_plugin and installed the gem and added that gem to the Gemfile like:

source 'https://rubygems.org'

gem 'locomotive_cms', '~> 2.0.1', :require => 'locomotive/engine'
gem 'locomotive_plugins'

group :assets do
  gem 'compass-rails',  '~> 1.0.2'
  gem 'sass-rails',     '~> 3.2.4'
  gem 'coffee-rails',   '~> 3.2.2'
  gem 'uglifier',       '~> 1.2.4'

  # If you run your engine on **Linux,** you also have to add the following gem
  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  # gem 'therubyracer', :platforms => :ruby
end

group :development do
  gem 'unicorn'
end

group(:locomotive_plugins) do
  gem 'locomotive_test_plugin'
end

According to the gem I can now edit any page in the CMS and add the following piece of liquid code:

{{ plugins.test_plugin.test }}

And I would expect the output to be 'test' but instead it shows nothing. It also doesn't display any errors like 'plugin not found' or something similar.

I've restarted the local server if someone would suggest that.

But where in the process did I went wrong - can anyone enlighten me on this problem.

Biketire
  • 2,019
  • 1
  • 23
  • 41

1 Answers1

2

First, the line

LocomotivePlugins::register_plugin(LocomotiveTestPlugin, "test_plugin")

is not needed. That is from an old version of plugins. As for your issue, Did you enble the plugin on your site? You need to go to the Settings page, there is a folded section called Plugins, under that there should be a entry with a checkbox. Make sure that that box is checked.

If the entry doesn't show up then the plugin is not being loaded properly. Make sure that your code is being loaded when you start up your server (add a print stmt at the top).

Charlie Greene
  • 465
  • 4
  • 11