Ecshop will automatically parse the paths of images, css files, and js files in the template file, but not all images, css files, and js files will be replaced,
For example, in the dwt template file:
The code is as follows: |
Copy code |
<Link href = "css/index.css" rel = "stylesheet" type = "text/css"> Will be automatically replaced <Link href = "themes/Template directory name/css/index.css" rel = "stylesheet" type = "text/css"> |
The css file that can automatically replace the path must start with the path css.
For example, in the dwt template file:
The code is as follows: |
Copy code |
<Script type = "text/javascript" src = "js/index. js"> </script> Will be automatically replaced <Script type = "text/javascript" src = "themes/Template directory name/js/index. js"> </script> |
The js file that can automatically replace the path must start with the path js.
For example, in the dwt template file:
The code is as follows: |
Copy code |
Will be automatically replaced |
Image files that can automatically replace paths must start with paths img
This automatic parsing makes it easy for us to put these css, js, img, and templates together without considering the actual path.
For the path replacement principles for images, CSS, and JavaScript in ecshop, see the last line of regular replacement in smarty_prefilter_preCompile () in the include/cls_template.php file:
The code is as follows: |
Copy code |
/* Add version information to the header */ $ Source = preg_replace ('/ /* Modify the css path */ $ Source = preg_replace ('/(<link \ shref = ["| \']) (? : \. \/| \.\.\/)? (Css \/)? ([A-z0-9A-Z _] + \. css ["| \ '] \ srel = [" | \'] stylesheet ["| \ '] \ stype = [" | \'] text \/css ["| \ ']) /I ',' \ 1 '. $ tmp_dir. '\ 2 \ 3', $ source ); /* Modify the js path under the js directory */ $ Source = preg_replace ('/(<script \ s (? : Type | language) = ["| \ '] text \/javascript [" | \'] \ ssrc = ["| \ ']) (? : \. \/| \.\.\/)? (Js \/[a-z0-9A-Z _ \-\.] + \.(? : Js | vbs) ["| \ ']> <\/script>)/', '\ 1'. $ tmp_dir.' \ 2', $ source ); /* Change the encoding type of the compilation template */ $ Source = preg_replace ('/<meta \ shttp-equiv = ["| \'] Content-Type [" | \ '] \ scontent = ["| \'] text \ /html; \ scharset = (? :.*?) ["| \ '] [^>] *?> \ R? \ N? /I ',' <meta http-equiv = "Content-Type" content = "text/html; charset = '. EC_CHARSET. '"/> '. "\ n", $ source ); } /** * Process database files */ Elseif ($ file_type = '. lbi ') { /* Remove meta */ $ Source = preg_replace ('/<meta \ shttp-equiv = ["| \'] Content-Type [" | \ '] \ scontent = ["| \'] text \ /html; \ scharset = (? :.*?) ["| \ ']> \ R? \ N? /I ', '', $ source ); } /* Replace the file encoding header */ If (strpos ($ source, "\ xEF \ xBB \ xBF ")! = FALSE) { $ Source = str_replace ("\ xEF \ xBB \ xBF", '', $ source ); } $ Pattern = array ( '/<! -- [^> | \ N] *? ({. + ?}) [^ <| {| \ N] *? -->/', // Replace the smarty annotation '/<! -- [^ <| >|{| \ N] *? -->/', // Replace html comments without line breaks '/(Href = ["| \']) \. \. \/(. *?) (["| \ '])/I', // replace the relative link '/((? : Background | src) \ s * = \ s * ["| \ ']) (? : \. \/| \.\.\/)? (Images \/.*? ["| \ '])/Is', // add $ tmp_dir to images '/((? : Background | background-image): \ s *? Url \()(? : \. \/| \.\.\/)? (Images \/)/is ', // add $ tmp_dir to images '/([\' | "]) \. \/Is ', // All paths starting with ../are corrected as null ); $ Replace = array ( '\ 1 ', '', '\ 1 \ 2 \ 3 ', '\ 1'. $ tmp_dir.' \ 2 ', '\ 1'. $ tmp_dir.' \ 2 ', '\ 1' ); |
Note: Although it is automatic, it is important to mention it. For example, ecsho.css will be parsed into themes/Template directory/ecshop.css.
Page css/ecshop.css will be parsed into themes/template/css/ecshop.css, while images will be parsed, img will not, js will be parsed, and javascript will not. The specific example is shown below: