Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2004-08-16 03:23:22

jmrhoades
Archived Plugin Author
From: Isobe-Cho, Mie-Ken, Japan
Registered: 2004-08-04
Posts: 14
Website

Insert javascript into <head>?

I have a plugin that is dynamically writing a small piece of javascript. It is getting called at the end of an article and so the javascript is inserted into that part of html page, namely inside the <pre><body></pre> tag. Is there anyway to insert the created javascript into the <head> tag from within the plugin?

I’m assuming you can’t since the article that contains the plugin comes after the <pre><head></pre> tag has been written. Please someone, prove me wrong. Thanks.

Last edited by jmrhoades (2004-08-16 03:24:33)

Offline

#2 2004-08-16 05:09:31

zem
Developer Emeritus
From: Melbourne, Australia
Registered: 2004-04-08
Posts: 2,579

Re: Insert javascript into <head>?

Create a tag in your plugin that spits out the appropriate code. Put that tag in the head section of the page.


Alex

Offline

#3 2004-08-16 05:22:41

jmrhoades
Archived Plugin Author
From: Isobe-Cho, Mie-Ken, Japan
Registered: 2004-08-04
Posts: 14
Website

Re: Insert javascript into <head>?

Mmmm, not quite, unless I don’t understand. Let me clarify. I’m placing the call to the plugin inside the article entry. I need the flexibility of being able to place the plugin tag independent of any page template. So I can’t simply place the plugin tag in “head section of the page.” What I’m asking is, is there a way to insert some in-article plugin generated javascript into the page the plugin happened to be called in? (Sorry for all the prepositions, hope that makes sense.)

Last edited by jmrhoades (2004-08-16 05:24:28)

Offline

#4 2004-08-16 05:44:22

zem
Developer Emeritus
From: Melbourne, Australia
Registered: 2004-04-08
Posts: 2,579

Re: Insert javascript into <head>?

A plugin can contain more than one tag. Create one function that spits out the javascript, and another that goes elsewhere.


Alex

Offline

#5 2004-08-16 05:56:09

jmrhoades
Archived Plugin Author
From: Isobe-Cho, Mie-Ken, Japan
Registered: 2004-08-04
Posts: 14
Website

Re: Insert javascript into <head>?

i’ll take your word for it, i just can’t fathom what you mean. “one function that spits out the javascript”, okay, got that. “and another that goes elsewhere”…huh? Goes elsewhere where?

that javascript is dynamic in that i’m passing it an array from the php inside the plugin. that array information is related to the specific article that contains the plugin tag.

I put the plugin in the article body because that’s the most direct way to associate an article with that plugin call.

i essentially just need to insert some stuff into the head of the html page. i’m wondering if plugins can have direct access to page templates. if that’s the case, then I could insert my javascript into any page regardless of the template, no?

please clairify any more if you can, thanks so much!

Offline

#6 2004-08-16 06:29:49

zem
Developer Emeritus
From: Melbourne, Australia
Registered: 2004-04-08
Posts: 2,579

Re: Insert javascript into <head>?

> i just can’t fathom what you mean. “one function that spits out the javascript

Last edited by zem (2004-08-16 06:35:27)


Alex

Offline

#7 2004-08-16 06:36:52

jmrhoades
Archived Plugin Author
From: Isobe-Cho, Mie-Ken, Japan
Registered: 2004-08-04
Posts: 14
Website

Re: Insert javascript into <head>?

Zem, you are indeed the bomb. Let me digest what you just said and give it another try. Thanks again!

Offline

#8 2004-08-16 06:52:57

zem
Developer Emeritus
From: Melbourne, Australia
Registered: 2004-04-08
Posts: 2,579

Re: Insert javascript into <head>?

Good luck. I should point out that I’m allergic to Javascript, so the syntax I wrote above is probably wrong. Hopefully it’s enough to demonstrate the idea.


Alex

Offline

#9 2004-08-17 05:18:38

datafirm
Archived Plugin Author
From: Seattle, WA
Registered: 2004-07-22
Posts: 35
Website

Re: Insert javascript into <head>?

> jmrhoades wrote:

> Mmmm, not quite, unless I don’t understand. Let me clarify. I’m placing the call to the plugin inside the article entry. I need the flexibility of being able to place the plugin tag independent of any page template. So I can’t simply place the plugin tag in “head section of the page.” What I’m asking is, is there a way to insert some in-article plugin generated javascript into the page the plugin happened to be called in? (Sorry for all the prepositions, hope that makes sense.)

This may be exactly what you are looking for:

http://flashrocket.worldoptimizer.com/article/7/textpattern-run-level

Offline

#10 2006-11-28 07:37:03

jesper
Member
From: Melbourne, Oz
Registered: 2004-03-05
Posts: 18

Re: Insert javascript into <head>?

Is this still the case with Textpattern 4.04?

I am trying to use the plugin rzm_googiespell and it needs 4 lines inserted in the header of the administration write new article page to reference 3 javascripts and a CSS for spell checking and it does not seem to work. It adds the lines right down near the end of the page.

Any help would be appreciated.

Offline

Board footer

Powered by FluxBB