Field that appears on every page


(Ryan Heneise) #1

There are a couple of fields that I’d like for the user to be able to customize that appear on every page. For example:

  • Google Analytics code
  • Javascript marketing code (Drip, Heap, etc)
  • Link to external stylesheets
  • Additional content

I thought about creating a node for these, but then they show up as content under admin. That might work, but it seems awkward for the user.

For now I’m just hard-coding these into the layout. Is there a way to have some sort of invisible node that would be user-editable, but now show up as a page in the node structure?


(Aaron Russell) #2

There isn’t any particularly elegant way of doing this right now. You can either:

  • Create an unexposed node, and add a before_node_filter that loads the node into an instance variable on every page. Like you say, this creates a “page” in the admin area so is a bit awkward.
  • Alternatively create you own config model and controller, and add it to the admin UI menu.

I have thought in the past about introducing a concept of “Global” nodes for this exact purpose. Global nodes would always be loaded on every request and somehow in the admin UI they are separated from normal content. It’s an idea that needs to be fleshed out a little more.


(Ryan Heneise) #3

For this project, I’m just going to use Google Tag Manager. I like that idea though - seems like there might be some global structure that could be inserted into every page at the layout level.