Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2014
    Posts
    42
    Plugin Contributions
    0

    Default PHP include in sidebox template

    Hi,

    I'm trying to do something that I'm thinking is simple but can't find an answer anywhere.

    I have a sidebox that I want to import an HTML file via PHP. It's a file that's somewhat organic and I don't want to meticulously hard code it every time it changes.

    I'm trying something like this -

    $content .= '<div>';
    $pagecontents = file_get_contents("./test/test.html");
    echo str_replace($pagecontents);
    $content .= '</div>';

    Does zencart already do this easily and I just haven't seen it yet? Thanks.

  2. #2
    Join Date
    Dec 2014
    Location
    SE TX
    Posts
    32
    Plugin Contributions
    0

    Default Re: PHP include in sidebox template

    maybe this
    Code:
    if(file_exists("./test/test.html"))$content.='<div>'.file_get_contents("./test/test.html").'</div>';

  3. #3
    Join Date
    Feb 2014
    Posts
    42
    Plugin Contributions
    0

    Default Re: PHP include in sidebox template

    Thanks for the idea SignTorch, but that didn't do it. It doesn't error, but it doesn't place the HTML. It's tiny, so it's not a size thing. I've tried absolute URLs and relative for the file location. Any other ideas? Should I be able to place HTML in a sidebox like this?

    Thanks again,

    Eric

  4. #4
    Join Date
    Jan 2004
    Posts
    66,364
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: PHP include in sidebox template

    Unfortunately for your scenario, sideboxes aren't written to pull in raw code from other files.

    But you can use HEREDOC syntax to drop your desired code into the (same, not separate) sidebox file , stuffing its data into the $content variable.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  5. #5
    Join Date
    Dec 2014
    Location
    SE TX
    Posts
    32
    Plugin Contributions
    0

    Default Re: PHP include in sidebox template

    I put this in test/test.html

    Code:
    <div style="border:1px solid #abc;color:#678;margin:2px;border-radius:0 0 5px 5px;padding:3px;text-align:center;">This is test/test.html</div>
    I put this at the end of tpl_categories.php

    Code:
      if(file_exists("./test/test.html"))$content.='<div>'.file_get_contents("./test/test.html").'</div>';
      else $content.="<div style='padding:4px'>file not found:<br />".getcwd()."/test/test.html</div>";
    I get this at the bottom of category sidebox

    Name:  sidebox.jpg
Views: 44
Size:  6.3 KB

    if ./test/test.html is not found, it displays the full path of ./test/test.html

    it works for me

    if ./test/test.html is a "URL" or "raw code", or not plain html, that was not spec'd in the question

 

 

Similar Threads

  1. Embed php template within another php template based on drop-down menu selection?
    By mcqueeneycoins in forum Templates, Stylesheets, Page Layout
    Replies: 12
    Last Post: 21 Jan 2012, 06:44 PM
  2. Include a custom php file in mainpage.php
    By BeautyHealth.com.cy in forum Templates, Stylesheets, Page Layout
    Replies: 6
    Last Post: 8 Nov 2010, 02:45 PM
  3. cant include template file?
    By END3RL3 in forum Installing on a Linux/Unix Server
    Replies: 4
    Last Post: 13 Oct 2009, 08:50 PM
  4. Php include
    By ericsc in forum Templates, Stylesheets, Page Layout
    Replies: 3
    Last Post: 26 May 2009, 05:32 AM
  5. Php Include
    By Jodz in forum Templates, Stylesheets, Page Layout
    Replies: 2
    Last Post: 4 Dec 2006, 05:44 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR