Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Reusable Text in HTML

Featured Replies

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

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.

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.

 

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 by AlexsDesign

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

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.