I know it sounds stupid but I tried that, but what I get on publish isn’t what I was expecting my example puts a link tag for an external style sheet before anything other style sheet and I wanted this line of code to be on its own line but If I use fwAddOpt I don’t get the result I expected
Here is part of the code in question:
var linkTag = fwDocument.fwTags.fwFind('link',fwItem);if (linkTag){ //check link tags exists//
var myTag = linkTag.fwAddEnclosing();
myTag.fwAddOpt('link rel="stylesheet" type="text/css" href="'+fwParameters["CSSLocation"]+'"',myTag); }
and what this produces is something that is not completely on its own line. This is its output (notice the link tag tacked to the end of my code:
What I have done in the past is to use a second fwAddRawOpt() (just empty) after the line of code where I add the stylesheet link. That forces a line-break if line-breaks are enabled, and ignores it otherwise. You’ll see this construction used heavily in my recent HTML5 Actions.
Walter
On Oct 10, 2012, at 10:01 AM, max wrote:
Hi Jo cheers for coming back…
I know it sounds stupid but I tried that, but what I get on publish isn’t what I was expecting my example puts a link tag for an external style sheet before anything other style sheet and I wanted this line of code to be on its own line but If I use fwAddOpt I don’t get the result I expected
Here is part of the code in question:
var linkTag = fwDocument.fwTags.fwFind(‘link’,fwItem);if (linkTag){ //check link tags exists//
var myTag = linkTag.fwAddEnclosing();
myTag.fwAddOpt(‘link rel=“stylesheet” type=“text/css” href="’+fwParameters[“CSSLocation”]+‘"’,myTag); }
and what this produces is something that is not completely on its own line. This is its output (notice the link tag tacked to the end of my code:
but if I use exactly the same code but use fwAddRawOpt like this:
var linkTag = fwDocument.fwTags.fwFind(‘link’,fwItem);if (linkTag){ //check link tags exists//
var myTag = linkTag.fwAddEnclosing();
myTag.fwAddRawOpt(‘<link rel=“stylesheet” type=“text/css” href="’+fwParameters[“CSSLocation”]+‘"/>’,myTag); }
this resulting output is this:
so hence why I was asking have I missed something…
the only real difference between the two is fwAddRawOpt
and fwAddOpt
Hi Max,
fwAdd and the variants all expect to write a tag to the output stream. Your code is writing markup which is why you are getting the default closing tag as well.
As far as Freeway is concerned you’ve just added a new tag to the page called ‘’.
Use fwAddOpt to add the link tag itself and then build the attributes on top of it. This will allow you to search for the link later in the tag tree.
var myLink = myTag.fwAddOpt("link",myTag); //adds the link tag and a reference to it
//add the attributes
myLink.rel = fwQuote("stylesheet");
myLink.type = fwQuote("text/css");
//etc
Hi Walter the method you have described is what I have done in the past but I always thought it was a bit of an odd thing to do… but if you are using it then I will carry on
Tim your method I am assuming is the correct way to do it and will keep that handy when I come to write the script again.
Max – don’t take what I wrote as gospel, I just did the expedient thing given my limited understanding of the API. I’m always learning, and hope to improve my Actions to be simpler and more robust as I do.
Hi Walter…
No I wont take it as gospel… :o) but if what I have done, which is the same sort of thing as you have described is ok, then for this occasion I wont bother changing it, but when I need to re-write that sort of thing again, I will take on board Tim’s Method.