ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Is there a way to include an EE template’s output in an external PHP script?

March 26, 2011 9:44am

Subscribe [5]
  • #1 / Mar 26, 2011 9:44am

    Michael C. (KKCJ)

    100 posts

    Just what the title says. The scenario is an online community website powered by EE 1.6.7, and separate SMF forums. I’m wanting to manage a list of links to community pages & sites in EE, and have that EE-managed list appear in the (non-EE) forums.

    The SMF forums have a feature that allows this in the other direction, the “SSI.php”, which - when included in an external PHP script - allows access to certain forum stats and data in that external script.

    Is there a way to accomplish the same thing with EE?

  • #2 / Mar 27, 2011 5:58pm

    Greg Salt

    3988 posts

    Hi Michael,

    There is no reason that you can’t call an EE template using AJAX for example (assuming that the SMF forums are on the same domain). You can also do something like this in an SMF file:

    <?php
    $output = file_get_contents("http://myeesite.com/my_template");
    //...parse output or whatever you need to do…
    echo $output;
    ?>

    Note that you may need to wrap this call in an output buffer.

    Does that help?

    Cheers

    Greg

  • #3 / Mar 27, 2011 6:06pm

    handyman

    509 posts

    My way is probably crude, but:

    <?
    include("http://www.hearth.com/myeesystem/index.php/articles/EEtemplate_to_bring_in");
    ?>

    simply including a EE template using PHP…..in a regular PHP page, works fine.
    This call, for instance, puts the most recent forum topics into the unrelated and non-EE front page of my site.

    http://www.hearth.com

    The EE template you call can have all the calls in it that you need to sort and select your data.

  • #4 / Mar 28, 2011 10:45am

    Sue Crocker

    26054 posts

    Thanks for the assist, Craig.
    Michael, does either Greg’s or Craig’s info help?

  • #5 / Mar 31, 2011 12:24pm

    Michael C. (KKCJ)

    100 posts

    My way is probably crude, but:

    <?
    include("http://www.hearth.com/myeesystem/index.php/articles/EEtemplate_to_bring_in");
    ?>

    simply including a EE template using PHP…..in a regular PHP page, works fine.
    This call, for instance, puts the most recent forum topics into the unrelated and non-EE front page of my site.

    http://www.hearth.com

    The EE template you call can have all the calls in it that you need to sort and select your data.

    That really works? Wow, I didn’t even try that due to being sure that the PHP include() was performed at the filesystem level, which would be before Apache processed EE’s index.php as a script. I’ll give that a try - thanks!

  • #6 / Mar 31, 2011 12:27pm

    Lisa Wess

    20502 posts

    That will work on some servers; but many (the majority, I believe) disallow PHP includes with a full URL for security reasons.  It’s worth a try, though!

    If that does not work, perhaps using Magpie or SimplePie to parse an RSS feed of the contents? These are both stand-alone PHP scripts that might fit the bill.

    Let us know how you get on!

  • #7 / Mar 31, 2011 12:46pm

    handyman

    509 posts

    That really works? Wow, I didn’t even try that due to being sure that the PHP include() was performed at the filesystem level, which would be before Apache processed EE’s index.php as a script. I’ll give that a try - thanks!

    Works for me - older server and newer (centos now, gentoo before).....but, as Lisa suggests, this might be because I use a dedicated box and have my own settings.

    I couldn’t say without making the attempt…if it would work with a relative path.

    No, doesn’t seem to work with relative paths…...

    As to urls and php, maybe it allows the same url? just not off-site urls?

    Try it and see, I guess!

  • #8 / Mar 31, 2011 12:51pm

    Lisa Wess

    20502 posts

    Yep, definitely try it and let us know!  Thanks Craig for all of your help. =)

  • #9 / Apr 03, 2011 8:29am

    Michael C. (KKCJ)

    100 posts

    Well I tried it and it doesn’t work for me - I get the following errors logged to the SMF forums into which I’m trying to include an EE template:

    include(): Failed opening ‘http://www.example.com/index.php/includes/top-nav’ for inclusion (include_path=’.:/usr/share/php:/usr/share/pear’)

    include(http://www.example.com/index.php/includes/top-nav): failed to open stream: no suitable wrapper could be found

    include(): URL file-access is disabled in the server configuration

    Based on that, can someone point me in the right direction for the settings I should ask the server admin to change?

  • #10 / Apr 03, 2011 2:44pm

    Greg Salt

    3988 posts

    Hi Michael C. (KKCJ),

    I believe that this is because of the allow_url_fopen configuration in your php.ini file. That setting will need to be on. Please ask your server admin whether that can be changed.

    Cheers

    Greg

  • #11 / Apr 04, 2011 2:02am

    Michael C. (KKCJ)

    100 posts

    Yup, showed them this thread and they concurred on the setting. They’re not willing to change that setting for security reasons, however, so I’ve been looking for alternative solutions. Any idea if I should be able to accomplish this using php’s cURL functions?

  • #12 / Apr 04, 2011 2:34am

    John Henry Donovan

    12339 posts

    Michael,

    I am going to move this thread to the CodeShare Corner as it is now more appropriate there.

    I am not familiar with cURL enough here to give you an example unfortunately

    I found some good explanations here and here though

  • #13 / May 20, 2011 5:39pm

    Michael C. (KKCJ)

    100 posts

    Michael,

    I am going to move this thread to the CodeShare Corner as it is now more appropriate there.

    I am not familiar with cURL enough here to give you an example unfortunately

    I found some good explanations here and here though

    Thanks John, those links put me on the path to solving this thing!

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases