Hi everyone, just a quick question and I suppose this is a really simple question (I hope) but is there a way to write raw code from a text field to the beginning of a document before the document type?
It probably sounds really dumb, but I cant see how you can write content to the publishing sequence that is outside any tags which Freeway produces.
If any one could shine a light on how this can done. I would be very grateful.
Like most things there are several ways to do this. This is the method
I generally choose;
//create an array of all of the page elements
var allContent = fwDocument.fwTags.fwFindAllContent();
//find the first item in the array
var firstItem = allContent[0];
//create a dummy marker before the first element (doctype)
var dummyMarker = firstItem.fwAddEnclosing("",false);
//get the text from the text field
var mymarkup = fwParameters["mymarkup"].fwValue;
//append my markup to the dummy marker
dummyMarker.fwAddRawOpt(mymarkup);
And no, it’s not a dumb question at all.
Regards,
Tim.
On 3 Nov 2009, at 22:11, pems wrote:
Hi everyone, just a quick question and I suppose this is a really
simple question (I hope) but is there a way to write raw code from
a text field to the beginning of a document before the document type?
It probably sounds really dumb, but I cant see how you can write
content to the publishing sequence that is outside any tags which
Freeway produces.
If any one could shine a light on how this can done. I would be very
grateful.
Hi pem
Tims is a neat way of doing it and the method I would recommend too but if you needed an alternative you can jump in before any tags are written so you could do this
// get ready to jump in before anything is published to the document
function fwBeforeStartHTML(){
var MyDoc= fwDocument.fwTags
// write the contents of the field before anything else is written
MyDoc.fwAddRawOpt(fwParameters["mymarkup"]);
Good call Max. I often overlook running code earlier in the publishing
cycle like this simply because I’m often messing with other stuff in
the document body or elsewhere on the page. If your markup is isolated
from the rest of the code on the page then adding it in at
fwBeforeStartHTML is a great solution.
Regards,
Tim.
On 4 Nov 2009, at 06:57, max wrote:
Hi pem
Tims is a neat way of doing it and the method I would recommend too
but if you needed an alternative you can jump in before any tags are
written so you could do this
// get ready to jump in before anything is published to the
document
function fwBeforeStartHTML(){
var MyDoc= fwDocument.fwTags
// write the contents of the field before anything else is
written
MyDoc.fwAddRawOpt(fwParameters[“mymarkup”]);
Hi Pems… as Tims pointed out the quick method is fairly limited because jumping in so early will mean that it doesnt know of any other action that could also push it’s content to the top of the document and so undo you first action. So best to use Tims example which could run at the end of the document writing sequence.
Thanks Tim and Max
I have had a quick experiment with yours Tim and it works as I hoped, apart from that the text is placed just after the document type. Is there something else I have to do to move it to before the document type or do I need to adjust your version in some way.
This should be a lesson to me to test the code I write from memory.
Here’s the code again with the corrected last line;
//create an array of all of the page elements
var allContent = fwDocument.fwTags.fwFindAllContent();
//find the first item in the array
var firstItem = allContent[0];
//create a dummy marker before the first element (doctype)
var dummyMarker = firstItem.fwAddEnclosing("",false);
//get the text from the text field
var mymarkup = fwParameters["mymarkup"].fwValue;
//append my markup to the dummy marker (corrected line)
dummyMarker.fwAddRawOpt(mymarkup, dummyMarker);
fwAddRawOpt in the last line takes a second (optional) parameter and
places the markup directly after the dummyMarker element.
Regards,
Tim.
On 4 Nov 2009, at 15:21, pems wrote:
Thanks Tim and Max
I have had a quick experiment with yours Tim and it works as I
hoped, apart from that the text is placed just after the document
type. Is there something else I have to do to move it to before the
document type or do I need to adjust your version in some way.