librelist archives

« back to archive

adding custom variables to config.yml

adding custom variables to config.yml

From:
aaron addleman
Date:
2012-04-21 @ 18:58
Hey everyone,

What is a good way to add more variables to the config.yml file? I have
been successful at doing the following in my app.rb:

module Nesta
    class Config
      @settings = %w[
        title aftertitle subtitle theme disqus_short_name cache content
google_analytics_code
      ]
    end

    class app
        helpers do
            def set_common_variables
            @menu_items = Nesta::Menu.for_path('/')
            @site_title = Nesta::Config.title
            set_from_config(:title, :subtitle, :google_analytics_code,
:aftertitle)
            @heading = @title
          end
      end
    end
end

Is there a better way to do this?

thanks in advance,
Aaron

Re: [nesta] adding custom variables to config.yml

From:
Graham Ashton
Date:
2012-04-23 @ 13:06
On 21 Apr 2012, at 19:58, aaron addleman wrote:

> Is there a better way to do this?

I just had a quick look. Nothing significantly better leapt out at me.

But do you really need to modify config.yml? If you need to vary the 
aftertitle thing in multiple sites (and access it in templates in a shared
theme), I can see why you'd want to add new stuff to config.yml.

If it's just for one site, I'd probably just write a helper method (rather
than create a new instance variable) and reference that in my templates. 
It could be simpler.

e.g.

    helpers do
      def aftertitle
        'value'
      end
    end

Re: adding custom variables to config.yml

From:
aaron addleman
Date:
2012-04-23 @ 13:47
Ok thanks!

On Monday, April 23, 2012, Graham Ashton wrote:

> On 21 Apr 2012, at 19:58, aaron addleman wrote:
>
> > Is there a better way to do this?
>
> I just had a quick look. Nothing significantly better leapt out at me.
>
> But do you really need to modify config.yml? If you need to vary the
> aftertitle thing in multiple sites (and access it in templates in a shared
> theme), I can see why you'd want to add new stuff to config.yml.
>
> If it's just for one site, I'd probably just write a helper method (rather
> than create a new instance variable) and reference that in my templates. It
> could be simpler.
>
> e.g.
>
>    helpers do
>      def aftertitle
>        'value'
>      end
>    end
>