July 23, 201214 yr Hi Guys, Is there a way of reusing text in HTML? I am trying to build a custom ebay page for my products and I have the same text on all of the pages like the delivery options or warranty. If I want to change one of these paragraphs, I have to modify every page which is a PITA. What I want to do is store the text in a central location and reference it from the html code. I appreciate I can do this with images but they don't warp when the page is resized and are not searchable unless ALT tags are used. Any help appreciated. Steve
July 23, 201214 yr if your server will allow, look into PHP and include statements http://php.net/manual/en/function.include.php
July 23, 201214 yr You may find teh php.net page difficult to understand if you are a beginner. Simply, Open up Notepad or a text editor (not Word) and cut the code that repeats in every page completely (as much or as little as you want, without doctype, html, head or body tags) and paste it into Notepad and save as an "include" file called menu.inc in the same folder as the main pages. You then have only one file to edit if the menu changes. Substitute the code you have cut out with PHP code <?php include ("menu.inc"); ?> in the main file and save it with .php filename extension instead of .html or .htm. [Most important] Do the same with other main pages where the menu repeats and name them with .php extension. Put the .inc "include" file in the same folder/directory as the main files. You can have several "include" files inserted in a page, just edit the filename and save separately.
July 23, 201214 yr Not sure myself how eBay stores work and whether you can use PHP, but if you can, then foolow the above advice from zed and Wickham. Basically keep those reusable sections of content/code in include files and link to them via the method above. That way you only ever have to change one instance of the snippet.
July 23, 201214 yr Author Thanks guys, it works locally so now need to test it on ebay once I get the include files hosted. Thanks again. Steve
July 23, 201214 yr save as an "include" file called menu.inc in the same folder as the main pages. You then have only one file to edit if the menu changes. Substitute the code you have cut out with PHP code <?php include ("menu.inc"); ?> in the main file and save it with .php filename extension instead of .html or .htm. [Most important] Sorry, but I disagree with the format you've advised... (But I could be wrong!)... As far as I am aware .inc files are not usually parsed by the server so the original php code is available for all to see if they view the file. This could cause issues if using sensative data (In this case, I assume it's not really sensitive data so you should be ok) BUT ... I would advise continuing to use .php extensions on your files .... and using the same include method <?php include ("menu.php"); ?> (( Another reason why I'm posting this here is incase someone comes along looking to learn PHP and puts a config file in the .inc format!! )) Edited July 23, 201214 yr by AlexsDesign
July 23, 201214 yr Good point but I don't think it makes any difference in this case whether you use .inc or .php for the "include" file as he only wants to repeat delivery options or warranty text which will show in the source file of the main pages after the include file is processed and inserted. It would matter if you wanted to process something like checking a password in the include file, which should then be .php
Create an account or sign in to comment