1

I have a component file that I only want to load once in my Volt project. Loading more than once will cause problems, similarly to loading the OpalRb library more than once. To clarify, I am loading this component file in a view file, and it keeps getting loaded because the line loading the component file keeps getting called every time the page gets hit:

{{ if condition }}
{{   require 'component/lib/file' # this line keeps getting called }}
{{ end }}

How do I set up my code so that I can load a component file only once?

Here is an example of my problem: https://gist.github.com/ylluminarious/f5ed3741d08528d87d26

GDP2
  • 1,948
  • 2
  • 22
  • 38

1 Answers1

1

You shouldn't be requiring anything inside of your view.

You should add the component as a dependency at the config/dependencies.rb file, and then use that component as it was a tag: <:component />

BTW:

Based on your gist, to me it looks like you should be creating a different route for each of your examples.

gabrielrios
  • 554
  • 1
  • 4
  • 12
  • Thanks for the answer. However, I'm still having a couple problems with using the component as a tag. I've updated the gist in my question to also show the `routes.rb` file and the `dependencies.rb` file. I also updated my view to have the component tag, but unfortunately, I'm still having a problem: now, I get a blank example. I think the problem is that I need to load specific files from my `examples` component, but I'm not sure how to fix this. – GDP2 Jun 29 '15 at 15:31