Forums / Templates, Stylesheets, Page Layout / How do I include a file with text or images into an EZ page or a Define Page?

How do I include a file with text or images into an EZ page or a Define Page?

Views: 1,315

Results 1 to 10 of 10
25 Jul 2014, 9:50 PM
#1
ibuttons avatar

ibuttons

New Zenner

Join Date:
Nov 2008
Posts:
51
Plugin Contributions:
0

How do I include a file with text or images into an EZ page or a Define Page?

I have products that require a lot of the same text and images (like the warranty information, colors, etc.). I am currently adding this information to each page individually. Updating this is a hassle, since I have to go each page and change it one-by-one.

I am looking for a better way. I want to store this common information in a file and then include that file into each product that it is appropriate for.

I have tried inserting a good ol' php include statement, but it doesn't seem to work. I am sure there must be a way to do this. Can anyone help with a specific example showing the exact format or a link to a reference page?

tia

25 Jul 2014, 10:21 PM
#2
ibuttons avatar

ibuttons

New Zenner

Join Date:
Nov 2008
Posts:
51
Plugin Contributions:
0

Re: How do I include a file with text or images into an EZ page or a Define Page?

Clarification: the title of my post mentioned EZ pages and Define Pages, but I want to include common info into the Product Detail pages as well.

26 Jul 2014, 1:21 PM
#3
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: How do I include a file with text or images into an EZ page or a Define Page?

Unfortunately I don't have ready access to some of the pages to which you are referring, but essentially, if every such product is located in a specific category for example, then if you used a category lookup function for the product_id and the return was your "designated" category, then you could include your text file that contains all of the html coded information where the file begins with ?> And ends with <?php

This is somewhat reverse of "normal" includes files, but if all you are including is "text" then it becomes easier than using echo commands, print commands, etc... for each and every line.
So text file might look like this:

?>Display this text everywhere it is included.<?php 

Then where you want to include the text,

if (includespecialtexthere) {
include('pathtotextfile/textfile.txt');
}

This is untested code, but seems appropriate based on understanding and history of working with php and ZC.

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

28 Jul 2014, 4:45 PM
#4
ibuttons avatar

ibuttons

New Zenner

Join Date:
Nov 2008
Posts:
51
Plugin Contributions:
0

Re: How do I include a file with text or images into an EZ page or a Define Page?

Thanks for your reply. However, that doesn't seem to help. It looks to me like the php include statement is being commented out by Zen Cart so that my common code is not even being brought in.

For example, when the code below is placed within the Product Description, what starts out as:

```

<?php include('commonfile.php');?>
it ends up displayed in a browser window (which is visible using *view source*) as the following. Notice the html comment code :yuck: that is wrapped around it:
``` <!--?php include('commonfile.php');?--> ```
The above code will work fine as long as the file is called directly from a browser (for example, <http://mydomainname.com/myfile.php>). Here is the code for myfile.php:
<body> <?php include('commonfile.php');?></p> </body> ```

Here is the code for the included file called commonfile.php:

common text to be included

Here are the results it produces when invoked directly from a browser with http://mydomainname.com/myfile.php), which is what I need:

common text to be included

So, the question is, how do I get Zen Cart to NOT comment out my php include statement? Or is there some other way to do an include on a Product Description page?

Surely, I am not the first or only person to want/need this, but I have searched all over the forums and the FAQs and Wiki, but all to no avail. Perhaps I just am searching for the wrong keywords/phrases? If anyone knows how to do, please share!

28 Jul 2014, 5:07 PM
#5
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: How do I include a file with text or images into an EZ page or a Define Page?

Okay, so this is a little different than first explained. Thought you were looking for the proper format to call the extra code from within code, not from within the description box. So, no one can not directly call/execute php code from within the description, but there is a way to have the description basically parsed and to therefore execute/include other information. Btw, and just to ensure that others are clear, you wouldn't want to call a file from within the main body of the ZC page that adds addition body tags to the existing page. I'll hhave to find it again. - think I tagged it in one of my favorites in case I ever had to desperately use that feature.

Realize, this option will require modifying the descriptions of multiple products as well, though hopefully just one more time. :)

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

28 Jul 2014, 6:09 PM
#6
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: How do I include a file with text or images into an EZ page or a Define Page?

There's a part of what I remember that can be found at: http://www.zen-cart.com/showthread.php?164232-Using-php-next-to-Category-descriptions&p=936736#post936736

From that link is some code to implement and a link to some more code that might help out. Predominantly it looks like swguy had worked through it several years ago. Might find more by searching for boilerplate in the forum, but hoping that the. Software is still available from his site as well.

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

29 Jul 2014, 3:35 AM
#7
dw08gm avatar

dw08gm

Totally Zenned

Join Date:
Sep 2008
Location:
DownUnder, overlooking South Pole.
Posts:
1,017
Plugin Contributions:
2

Re: How do I include a file with text or images into an EZ page or a Define Page?

I may be wrong but I suspect the php command should be "require" or "require_once", instead of "include".

Use Developers Tool Kit for examples of use.

Hope this helps

29 Jul 2014, 4:05 AM
#8
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: How do I include a file with text or images into an EZ page or a Define Page?

dw08gm:

I may be wrong but I suspect the php command should be "require" or "require_once", instead of "include".

Use Developers Tool Kit for examples of use.

Hope this helps

Any of the three work for bringing code into a php program. Require means that the code must be included or else a failure/error will occur, include means to bring it in, but if it is unsuccessful execution can continue. Each has a once option, that basically prevents the file from being brought in mmore than once which would cause an error of it's own.

In this situation, at least with the code above, the attempt has been to incorporate code into the description instead of "before" or "after" it in the code itself.

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

29 Jul 2014, 4:20 AM
#9
dw08gm avatar

dw08gm

Totally Zenned

Join Date:
Sep 2008
Location:
DownUnder, overlooking South Pole.
Posts:
1,017
Plugin Contributions:
2

Re: How do I include a file with text or images into an EZ page or a Define Page?

mc12345678:

Any of the three work for bringing code into a php program. Require means that the code must be included or else a failure/error will occur, include means to bring it in, but if it is unsuccessful execution can continue. Each has a once option, that basically prevents the file from being brought in mmore than once which would cause an error of it's own.

In this situation, at least with the code above, the attempt has been to incorporate code into the description instead of "before" or "after" it in the code itself.

Thanks for clarity.

30 Jul 2014, 1:21 AM
#10
ibuttons avatar

ibuttons

New Zenner

Join Date:
Nov 2008
Posts:
51
Plugin Contributions:
0

Re: How do I include a file with text or images into an EZ page or a Define Page?

Well, I have found a kinda kludgy way to do what I want, but it seems to work. Below is an example, in case someone else wants/needs it, too.

  1. First, create a file containing the common code that you want to insert on multiple products. Here is a simplified example where I want multiple products to all say the same thing about the colors that are available. For this example, this code will be stored in the file called [myfilename.html]
<br>It comes in 3 lovely colors:  red, green, and blue. blah blah blah.<br>
  1. Next, login to your Zen Cart Admin, go to Categories/Products, and edit each Product one-by-one in Plain Text mode. Insert an iframe in the description field where you want the common code to appear. Be sure to set the height, width, and specify the name of the file with the common code on the iframe statement:
<p>
	This widget is really great! 

	<iframe frameborder="0" seamless width="xxx" height="yyy" src="http://[mydomainname.com]/[myfilename.html]"></iframe>

	You will just love it!
</p>

So this produces the following output when viewed in a browser:

This widget is really great!
It comes in 3 lovely colors: red, green, and blue. blah blah blah.
You will just love it!

You should probably also do one more thing and that is add a link statement to a css definition file at the top of the included file. This because the iframe doesn't pass along css definitions to its contents. No worries, though, as you can easily do this with a statement that looks like this:

<link rel="stylesheet" type="text/css" href="/includes/templates/css/[stylesheetname.css]" />

If you want to see a working example, browse on over to http://keylessentrylocks.com/index.php?main_page=product_info&cPath=1&products_id=98. Click on #5. Lock Colors in the accordion-style control to see some stuff that was included as described above. And while you are there, if you see something you like, feel free to buy it! (sorry, couldn't resist a bit of shameless site promotion :blush:)

One problem with this method is that you need to specify a height and width or you will get scroll bars. Sometimes that is ok, but sometimes not. Another problem is that I want to use a Dreamweaver jQuery tab control (which is similar to the accordion control on the page now), but that one doesn't seem to work. Not sure why yet. Enlighten me if you know! :smile:

This example shows how to insert common code elements into a Product Description file, but I would expect it will also work with EZ Pages and Define Pages. I just haven't tested that yet.

If you know of an easier way, please do let us all know.

Good luck and hope this is helpful to someone.