I've noticed that when i include stylesheet in a template file (e.g. account_login.tpl) the tag is automatically moved into section of the page. Can anyone tell me where's the code responsible for that? I'd also like to 'move' the tags containing javascript files to same way.
Thanks for help.
Thanks for help.
Hmm.. I don't see that happening at all at my site. Note the source shows the default.css at the top, but the product.css in the middle. I wish it would do what you say it does actually, but I think the css should be setup differently anyway to be automatic, so that proper overrides can take place, without hardcoding the css file in the tpl file, and it would keep it all in the head tag
Also, the css needs to move to the head tag so that it can properly validate, as it is highly illegal the way it is now
So I guess what I'm saying is that css and js should be handled a lot differently. We will see what changes are in store for 0.8 and what may need to be done to improve on the system.
I already have a plan on paper for the css stuff in my override system discussion topic:
http://forum.opencart.com/index.php/top ... ml#msg7771
js would actually follow the same path.
Also, the css needs to move to the head tag so that it can properly validate, as it is highly illegal the way it is now

So I guess what I'm saying is that css and js should be handled a lot differently. We will see what changes are in store for 0.8 and what may need to be done to improve on the system.
I already have a plan on paper for the css stuff in my override system discussion topic:
http://forum.opencart.com/index.php/top ... ml#msg7771
js would actually follow the same path.
Last edited by Qphoria on Wed Aug 20, 2008 11:25 pm, edited 1 time in total.
Hm, I'm sure it's working the way i wrote, but only for the CSS links. I think I'm using v 0.7.7. In the store demo it doesn't work actually - the links are in the middle, as You said (older version?). In my store css link is behaving as i'd expect (moving to ) but Javascript not. I wish someone could tell me why it's happening and show some code, so i can fix the javascript tags too. I haven't modified code to do that, it's default behavior.
Yeah, that's it. Thanks Brucebruce wrote: if you are using the xhtml contribution (possibly built into 0.7., this is what it does

Code: Select all
static function linkReordered( $str ) {
//return $str;
$headEnd = stripos( $str, "</head>", 0 );
if ($headEnd === FALSE) {
return $str;
}
$result = substr( $str, 0, $headEnd+strlen("</head>") );
$previousPos = $headEnd + strlen("</head>");
while (TRUE) {
$linkStart = stripos( $str, "<link", $previousPos );
if ($linkStart === FALSE) {
$result = $result . substr( $str, $previousPos );
break;
}
$linkEnd = stripos( $str, ">", $linkStart );
if ($linkEnd == FALSE) {
$result = $result . substr( $str, $previousPos );
break;
}
// insert everything from $previousPos to $linkStart at the end of $result
$result = $result . substr( $str, $previousPos, $linkStart-$previousPos );
// insert everything from $linkStart to $linkEnd+1 inclusive to $result at postion $headEnd
$result = substr( $result, 0, $headEnd ) . PHP_EOL . substr( $str, $linkStart, $linkEnd-$linkStart+1 ) . PHP_EOL . substr( $result, $headEnd );
$previousPos = $linkEnd+1;
}
return $result;
}
Last edited by boraz on Thu Aug 21, 2008 6:50 pm, edited 1 time in total.
Moving the tags into the section is done by the OpenCart XHTML plugin module which I wrote a while ago for OpenCart version 0.7.7. Please be aware that I have never tested it for OpenCart 0.7.8 so no guarantee it will even work with that version. The code which relocates the tags can be found in the fileboraz wrote: I've noticed that when i include stylesheet in a template file (e.g. account_login.tpl) the tag is automatically moved into section of the page. Can anyone tell me where's the code responsible for that? I'd also like to 'move' the tags containing javascript files to same way.
Thanks for help.
/library/environment/response.php
which has been modified by the XHTML plugin. The function where it happens is called linkReordered
Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig
JNeuhoff could you also add tag support to this function? I've tried to modify it and ended up with this (just added some variables):
Code: Select all
static function linkReordered( $str ) {
//return $str;
$headEnd = stripos( $str, "</head>", 0 );
if ($headEnd === FALSE) {
return $str;
}
$result = substr( $str, 0, $headEnd+strlen("</head>") );
$previousPos = $headEnd + strlen("</head>");
while (TRUE) {
$linkStart = stripos( $str, "<link", $previousPos );
$scriptStart = stripos( $str, "<script", $previousPos );
if ($linkStart === FALSE || $scriptStart === FALSE) {
$result = $result . substr( $str, $previousPos );
break;
}
$linkEnd = stripos( $str, ">", $linkStart );
$scriptEnd = stripos( $str, "</script>", $scriptStart );
if ($linkEnd == FALSE || $scriptEnd === FALSE) {
$result = $result . substr( $str, $previousPos );
break;
}
// insert everything from $previousPos to $linkStart at the end of $result
$result = $result . substr( $str, $previousPos, $linkStart-$previousPos );
// insert everything from $linkStart to $linkEnd+1 inclusive to $result at postion $headEnd
$result = substr( $result, 0, $headEnd ) . PHP_EOL . substr( $str, $linkStart, $linkEnd-$linkStart+1 ) . PHP_EOL . substr( $result, $headEnd );
$previousPos = $linkEnd+1;
}
return $result;
}
Haven't tried it, but maybe you could just clone the function and make a new one for script:
Then just add the call for it underneath the call for the link one
Code: Select all
static function scriptReordered( $str ) {
//return $str;
$headEnd = stripos( $str, "</head>", 0 );
if ($headEnd === FALSE) {
return $str;
}
$result = substr( $str, 0, $headEnd+strlen("</head>") );
$previousPos = $headEnd + strlen("</head>");
while (TRUE) {
$scriptStart = stripos( $str, "<script", $previousPos );
if ($scriptStart === FALSE) {
$result = $result . substr( $str, $previousPos );
break;
}
$scriptEnd = stripos( $str, ">", $scriptStart );
if ($scriptEnd == FALSE) {
$result = $result . substr( $str, $previousPos );
break;
}
// insert everything from $previousPos to $scriptStart at the end of $result
$result = $result . substr( $str, $previousPos, $scriptStart-$previousPos );
// insert everything from $scriptStart to $scriptEnd+1 inclusive to $result at postion $headEnd
$result = substr( $result, 0, $headEnd ) . PHP_EOL . substr( $str, $scriptStart, $scriptEnd-$scriptStart+1 ) . PHP_EOL . substr( $result, $headEnd );
$previousPos = $scriptEnd+1;
}
return $result;
}
While it is necessary to place links to external stylesheets in the head for standards compliance, the same is not true for javascript, because a script can be placed anywhere in the HTML code. Inline scripting is, after all, part of the HTML specification.
Modules for OpenCart 2.3.0.2
Homepage Module [Free - since OpenCart 0.7.7]
Multistore Extensions
Store Manager Multi-Vendor/Multi-Store management tool
If you're not living on the edge ... you're taking up too much space!
Precisely. That's why I didn't include tags in the relocation. I am not even changing the ampersands within tags.fido-x wrote: While it is necessary to place links to external stylesheets in the head for standards compliance, the same is not true for javascript, because a script can be placed anywhere in the HTML code. Inline scripting is, after all, part of the HTML specification.
Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig
Who is online
Users browsing this forum: No registered users and 3 guests