Extra Extra Header Content

Permalink
Is there a way to create an additional attribute field for placing JavaScript into the header? I have a client who wants only certain pages with tracking code. I have already created hundreds of pages thinking all pages were going with tracking. Some of the pages already use the extra header content attribute.

I first tried adding the JS code to the extra header content on multiple pages using the dashboard/sitemap/search/ and editing page properties from there. Unfortunately, that overwrote the existing extra header content I used on some pages. If I could add a similar field for the JS code and just add it to a selection of pages - that would be great. Unfortunately, when I tried to create an attribute just for this (same settings as extra header content attribute) and added to the page header set, it is not ending up in the header source code. I don't really want to go with using another page type just for this and don't want to edit a ton of pages individually. Is there another solution to this?

On another note, it would be great if I could exclude certain pages using extra header content attribute in the dashboard/sitemap/search/. I don't see a way to exclude something from search results. That would help minimize the problem if I could not overwrite what's already there.

Thanks,
Hope

HopeL
 
HopeL replied on at Permalink Reply
HopeL
Has no one had a similar situation? So there's no way to do what I was trying to do with a page attribute - add extra header content for JS code?
JohntheFish replied on at Permalink Reply
JohntheFish
Have a look at my Load jQuery.UI addon.
HopeL replied on at Permalink Reply
HopeL
Thanks, John. I did see that add-on but wasn't sure if it was what I needed. I'll have a look.
JohntheFish replied on at Permalink Reply
JohntheFish
I made the last post from my mobile, so could't add much detail. I didn't mean for you to use the block directly, but by reading the code you could understand 2 methods of adding scripts (or css) to the headers of selected pages (or all pages).

The 2 methods demonstrated in the addon are:

- A block that adds the headers when included on the page (can be placed in a regular area for one page or a global area for all pages). The block controller on_page_view() event handler method adds the headers.

- An attribute that, when added to a page, results in the headers being loaded. The package controller on_start() and on_before_render() event handler methods look for the attribute and add the headers if it is present.

If the asset you require is jQuery.UI, then you could use the addon as-is. Pick just one of the methods most suited to your requirement and write your own special to purpose package to do the same.