Using PHP "include" in category & product description
I have several product lines that come in kits of various configurations. Example: Product line 1 has 4 components, A, B, C, and D. Kit 1 includes A, B, and C. Kit Two includes A, B, and D. Kit 3 includes only A and D.
I want to have a file with a detailed description of each component -lets say a_desc.php, b_desc.php and so on, so in the description of Kit 3 I could have
<p> Kit 3 includes the following components:</p>
<?php
include("a_desc.php");
include("d_desc.php");
?>
That way I would only have to update the detailed description of a component in one place to have all kits updated.
I've tried this with my _desc.php file located in a couple of different directories and changing the php include statement to use every possible combination of directory info from just filename all the way out to http://...filename, and nothing has worked.
Questions:
1. Can this be done without more trouble than its worth? (If not, the rest of the questions don't matter, but I'd appreciate alternate suggestions.)
2. Where is the best place to put the -desc.php files to avoid troubles with permissions, and should they be .php or .html by name.
3. Should they be a standard html file format internally, or does there need to be any PHP tags or code added?
4. are the above example include statements the correct way to include these files in the description, or is there a better way? If these are the best way, any tips you could provide (especially regarding designating the path)would be appreciated.)
Re: Using PHP "include" in category & product description
Re: Using PHP "include" in category & product description
You cannot include PHP in the description text (or any component that is basically html that ZC parses into a page. This includes defined pages, EXZ pages and all description texts (product, category, etc)).
The reason is that in the case of description text, the data is stored in the database. The core php cannot read the code BEFORE it is parsed - (because it simply isn't there to read). The data is brought into the compiled HTML page only AFTER all the php has done its work.
As haredo indicates, there may be something you could achieve with the basic concept of boilerplate text... Talk to Scott Wilson (swguy) about this.
Re: Using PHP "include" in category & product description
Thanks much to both of you. Now I understand why it won't work the way I was trying to do it. If I'm understanding the other page referenced correctly, that's a good tip, but my product descriptions often contain lists and specification tables. I don't think the boilerplate text will help, unless I can put full HTML code in the string definition... would that work, or would it just show up in the description with the tags visible?
Re: Using PHP "include" in category & product description
You can insert most of the (basic) HTML tags into description text, and they will render the text (or content) as you would expect HTML to be rendered in a browser.
Hyperlinks <a href=...>, Image Source Tags <img src=...>, Ordered Lists <ul><li>, font size, colour, etc, ect - - - will all show up correctly.
Many people (myself included) construct such description text in external HTML editors, capture the code portions we want onto clipboard, then "paste" that code into the wysiwyg editor (after toggling to HTML mode).
Remember, the text (html formatted or not) is STATIC, and will have to be altered manually.
There may be a way to generate additional dynamic content using PHP, but this would need some thought - not only additional code in the template.php files, but probably additional fields in the database where you would manage the "associations" between the product data sets. So you would also need additional facilities in the product admin side as well (becomes complicated... !)