I would using includes for templating a PHP website. I intend to create a header.php file which will contain the doctype, head tag, and everything upto the body tag. My problem is that I don't want the same title or same javascript/css files on every page. What would be a good way to make this more dynamic so that I can set the tile for a page and only include the javascript, css files that I want to include ? I wouldn't be using any frameworks or template engines for this project. So far I have come up with this,feedback would be greatly appreciated:
http://pastebin.com/drdKnEn2
I would suggest, keep it simple,,, dont use php function to include metaname and favicon nd stuff.
I would rather keep writing these stuff on every page... coz everypage on website is not the same... and if you are using dynamic php, there wont be too many pages! It will look neat and clear to understand/access.
Related
While i am still learning css html5 and Jquery, combined with the information from the internet, i came up with a idea to program the css in to different chapters, and call them in to the head section when need it.
from my understanding, via google it is faster to load css styles in the head as a <style></style>.
This way i will only have the css at the page that i need, and it will be better readable for me, becouse i dont use html css styling in dreamweaver anyway.
My css is now so big it is taking tomutch time to find it all.
even with dreamweaver search box.
Does any one have experience with this, or see any problems i might incounter?
Thanx in advance..
The only way to create structure if you're working in a big php project is to save a blank html page, load the existing css on to that page, use the css options/panels in dreamweaver and load the body parts you need in there.
If your using a dynamic css location link, other wise, i think dreamweaver will do just fine in php.
Not sure becouse i never used it that way...
Situation
i try'd to make more sence doing it this way, but i have just put everything back, becouse i got a unknown error, did not investigate it further. And the <style></style> has the highest level of design, meaning all the rules that where set, will be overwritten, things will get complicated fast if you start moving parts aspecialy if have a multi css styling site, so it is not recommended if you already have a big project, do it from the start...
Edit * 27-11-2015
I found the solution, i am using classes to slowely but surely replace the css file...
I have a js file that has the code for navigation for a site with ~600 pages..
Now I want to change the menu(colors, background, links etc) and I don't want to edit the JS file as the code here is like using images for the menu..so I was thinking that I will create a php file or html file and then call it inside that js file. Is this something possible?
Please advise.
You could have the js render an iframe instead of an img and pass along the url to the php/html.
You need to understand the difference between PHP, HTML and JS. They each occupy a different domain in web programming. PHP is for server side logic, HTML is a structural language and JS is an action-oriented language intended to function on top of the HTML that exists in the page (and may be rendered in JS).
All programmers have at one point tried to "hack" code like you are doing, by trying to find a band-aid fix to a complicated solution. It is not worth it. You will lose performance in the best of cases and either fail outright or lose browser compatibility and user interface quality the vast majority of the time.
In short, take your time and edit the JS. You can always do a find/replace on images to strip them out and insert CSS class declarations in their place. Do it right and you'll save yourself a big headache later on.
I'm currently working on a custom CMS, (just a basic layout split into templates, header.php, footer.php etc.). I'm trying to avoid loading my scripts within the header, but some of them, like a jQuery plugin that populates a gallery with photos and videos, need to be loaded first. Right now, I'm writing my functions after the loaded scripts within the footer. It works, but it's far from optimal because not all script blocks and JS files are need for every template, but I can't seem to find a way to split script blocks between templates without loading JS within the header. Is there a best practice for this sort of situation, or am I stuck with loading scripts within the header?
Thanks in advance!
For best practices, as far as I know, javascripts are ideally placed at the bottom of the page since most would only function when all elements of the page have loaded.
jQuery plugins, I have used so far work, even when placed below the main content of the HTML. Since most of these plugins are enclosed with $(document).ready() they won't really do anything until the page completely loads even if they were loaded in the header. The only heads up would be to place jQuery.js above jQuery plugin scripts for the plugins to work.
I'm starting to get into a lot more JavaScript thanks to a few UI frameworks such as KendoUI and Dojo/Dijit and I'm trying to integrate these with my custom MVC framework. However, all of their examples have the JavaScript embedded in <script></script> tags along with the HTML, which is fine and just means that the code gets dumped in my Views.
I was just wondering if there was some 'standard' or 'more acceptable' method of presenting custom JavaScript code in my projects. Is embedding the code in the HTML the best way to do it, or is it considered nicer to store the JavaScript in .js files and link to it from the HTML?
Use a script tag, for example <script src="foo.js"></script>
Ideally use a minified version, for example <script src="foo.min.js"></script>
If you're building a website, also look into ways of caching the file (and uncaching if the files changes), for example by using a datestamp in the file name.
Some programming frameworks have ways to automatically combine and minify all the JavaScript files for a page. For example, Rails has an asset pipeline that handles this for you.
This is the style I use,
1).I usually link js libs ( jQuery and etc.. ) using <script src="libURL"></script>
reasons :
This caches the js lib. Most of the pages in my site will be
using that particular js lib and caching will reduce the loading
time and bandwidth use.
Once I got a newer version of the js lib I have to just replace
the old one with the new. No need to change stuffs page by page!
2).I embed scripts using <script>//codes here</script> method when those codes are specific to that particular page.
Reasons:
To make sure I will not mess up with my codes! ;-)
These codes have more tendency to be changed while updating the site,therefor it's good not to have them cached.(But no use if your site is not under going rapid changes!)
You should use external <script> tags to allow the browser to cache the scripts and save bandwidth.
Optionally, you can also automatically minify them.
i'm looking for a way to display a web page inside a div of other web page.
i can fetch the the webpage with CURL, but since it has an external stylesheet when i try to display it, it appears without all his style properties.
i remember facebook used this technique with shared links (you used to see the page that was linked with a facebook header)
did some unsuccessful jquery tests but I'm pretty much clueless about how to continue..
i know this can be done with frames but i always here that it's good practice to avoid frames so i'm a bit confused
any ideas how to work this out?
If you want to display the other website's contents exactly as they are rendered in that site then frames are, in this case, the best (easiest) way to go.
Facebook and Google both use this technique to display pages while maintaining their branding / navigation bar above the other site.
I am going to guess that Facebook still used an iFrame, just with no borders and a well placed header outside of it. The reason I am guessing that is because if the outside page has its own style sheet, there is a high probability that your styles and their styles will clash and not show things properly.
In order for the styles not to clash everything on both ends would have to be extremely detailed, not just generic styles applied to all paragraphs etc...
i agree that using frames would probably be the best solution for you problem.
but if you still want to avoid frames and put the contents into a div with the id externalConent, you could request the stylesheets the same way you get the other contents and prefix every rule in them with "#externalContent ". save these stylesheets to your server and include them in your page. with a few more customizations, that should work.
i have to admit this solution does sound quite strange... well, it is.
but it's the only way i see to do what you're asking for.
If you are unable to use a frame or iframe, try:
extract the HTML inside the BODY and inserting it into the destination DIV
extract the and sections at the header
Is not very clean though, but it will definitely work, you can insert a phpBB forum into another dynamic way using this technique, take a look at http://www.clearerimages.com/forum/ for an example.