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.

EE Templates vs. PHP includes?

August 21, 2008 9:00am

Subscribe [5]
  • #1 / Aug 21, 2008 9:00am

    turnstyle

    47 posts

    Hi all, I’m very new to EE, and have a somewhat unusual question—from a CMS, I most need a Web interface to manage content and integrated features like a blog and a forum (‘integrated’ meaning, sharing the same user accounts, so a logged-in member of the blog is also a logged-in member of the forum).

    I don’t really need a Web interface to edit the site templates—though I do understand that EE’s templating system is highly regarded.

    Essentially, my question is this: instead of putting a block of HTML with EE markup into the templates, can my templates instead have just a PHP include() and then make calls to include()‘ed functions, passing the query results retrieved EE into those PHP functions?

    (I do see that PHP within a template can be a concern if other users are permitted to edit the templates—but that doesn’t seem to be an issue for me).

    To me, the advantages seem to be:

    1) I’m personally more comfortable in PHP than EE, so I can work more quickly—and, generally, more folks know PHP than EE.

    2) The page rendering logic, if in PHP rather than EE, would be much more portable—meaning, I can easily port the same functions to some other system should I ever need to.

    3) If there is less HTML and EE markup in the template, and it’s mostly all processed by include()‘ed PHP functions, it seems perhaps that could also be a performance benefit.

    I hope my question makes sense! I know that people *love* EE’s templating system—but in my case, what I really need is *content* management with an attached blog & forum—and I also happen to be very comfortable with PHP (and have never previously used EE markup).

    Thanks so much if you have any thoughts to share!

  • #2 / Aug 21, 2008 9:08am

    Ingmar

    29245 posts

    I don’t really need a Web interface to edit the site templates

    You certainly don’t have to use it: many people are saving their templates as files, and work with them directly.

    ... can my templates instead have just a PHP include() and then make calls to include()‘ed functions, passing the query results retrieved EE into those PHP functions?

    Not sure what you mean, exactly? Do you mean using templates that consist of nothing but <?php include ‘/path/foo.php’; ?> If so, what do you gain? To make use of EE’s function you will generally need to use EE tags; it doesn’t matter in which template or file.

    If you plan not to use EE for large parts of your site, on the other hand, perhaps you would be better off using native PHP in the first place? In that case, be sure to check out CodeIgniter.

  • #3 / Aug 21, 2008 9:16am

    turnstyle

    47 posts

    Rather than just something like:

    <?php include ‘/path/foo.php’; ?>

    in the EE template, I mean something more like (as I don’t yet know EE markup, this is pseudo code):

    <?php
    include ‘/path/foo.php’;
    header({results from EE});
    pagecontent({result from EE});
    footerer({result from EE});
    ?>

    or even just:
    <?php
    include ‘/path/foo.php’;
    page({result from EE});
    ?>

    ie, I’d be using EE to manage all the content—but would be passing the results to included functions, rather than rendering them through HTML and EE markup in the template.

    See what I mean? Thanks again!

  • #4 / Aug 21, 2008 9:25am

    Ingmar

    29245 posts

    in the EE template, I mean something more like (as I don’t yet know EE markup, this is pseudo code):

    <?php
    include '/path/foo.php';
    header({results from EE});
    pagecontent({result from EE});
    footerer({result from EE});
    ?>

    Be my guest:

    {embed=includes/header}
    <!-- Body -->
    {embed=includes/footer}

    The only thing I don’t get is “result from EE”. If you want EE to display some content, you’ll probably want to use an exp:weblog:entries tag.

    I’d be using EE to manage all the content—but would be passing the results to included functions, rather than rendering them through HTML and EE markup in the template.

    I think you’d make it all much more complicated than it really needs to be. Really, if you know XHTML and PHP, you’ll be using EE syntax within a few minutes.

  • #5 / Aug 21, 2008 9:41am

    turnstyle

    47 posts

    Here’s what I mean by results from EE…

    Let’s say we have a page, http://www.site.com/page/hello-world

    EE is going to query the database for the ‘hello-world’ page content (title, text, etc.)—and then it’s going to render the EE template—in the traditional EE case, by sprinkling the ‘hello-world’ query results here and there in the template, via EE markup within the HTML in the template.

    My thought is to still have EE query the database for the ‘hello-world’ page content—but that then it would pass the results to a an included function—so EE is still retreiving the data, but it then simply passes that data over to a PHP function which has all the page rendering logic.

    So: 1) all the page logic can be controlled via pure PHP, 2) the included functions are portable, and 3) it seems this should be faster as compared to parsing HTML for EE markup.

    Do you better see what I mean? Thanks again…

  • #6 / Aug 21, 2008 10:50am

    Boyink!

    5011 posts

    My $0.02?

    You’re proposing to try and both work with and against ExpressionEngine at the same time, and like any situation where both ends are being pulled or pushed at the same time it will lead to stress and possibly things breaking.

    I’d look into going one of two directions -

    1. Take another step to the left and go the CodeIgniter route.
    2. Take another step to the right and let EE do the job it was designed to do.

    Either way - I’d recommend spending some time learning how EE works natively before trying to outthink it.

  • #7 / Aug 21, 2008 11:36am

    turnstyle

    47 posts

    Hey Mike, thanks (fwiw, we actually spoke about this site a little while ago),

    I’m certainly not trying to “outthink” EE—rather, I simply have a slightly different set of priorities that might be typical. Meaning, I don’t need EE to process templates if I can accomplish the same via naitve PHP—however, I really do need the *content* management interface (ie, as opposed to needing a *template* management interface)—and, for us, there are advantages to keeping the templates coded as system-agnositc PHP functions.

    ie, for us, it is a plus if all the page rendering logic is independent of the CMS—but, per my posts above, I also understand that folks really like EE’s template system, and I’m sure it is great.

    But what we need is a simple way of managing the *content*—along with an integrated blog & forum—we don’t need to be able to adjust the templates themselves via a front end—and per above, are benefits to keeping the template logic independent—that all said, I’m really very interested to know why this approach doesn’t make sense.

    Thanks again,  -Scott

  • #8 / Aug 21, 2008 1:11pm

    Lisa Wess

    20502 posts

    turnstyle - I would recommend reviewing Derek’s posts in Why use templates?

    I’ll quote my favorite part:

    Templates are your site in ExpressionEngine.  Any effort expended away from this approach is energy spent working against the application…

    In your other posts as well you seem to want to fight against ExpressionEngine rather than leveraging its power.  If you are so intent on doing this, why not simply build your own custom app, say using CodeIgniter?

  • #9 / Aug 21, 2008 4:42pm

    turnstyle

    47 posts

    I don’t know CodeIgniter—does it offer a Web admin interface to maintin content, and an integrated blog/forum that users access via a single logon?

    imho, a good tool is mindful that different people will want to use it differnt ways, and my other question is perfectly valid: we want URLs that use numbers to indicate parts that are named with a numnber—we are reluctant to change our naming scheme just because the CMS says so.

    But please let me try asking this way:

    Do you see that if our templates exist as included PHP functions, that we would then have a much more portable and CMS-agnostic design? Do you see what I mean by that?

  • #10 / Aug 21, 2008 5:33pm

    Derek Jones

    7561 posts

    I think everyone here understands what you’re driving at, but it’s entirely a false assumption.  You’re still restricted by the bounds of ExpressionEngine’s database schema, control panel functionality, and intent.  This post in particular from the thread Lisa linked should be sufficient to make you decide to either use EE as intended, or to use a different tool.  You’re not going to be CMS-agnostic, because to get your data from ExpressionEngine, you’re either going to have to use tags anyway, or spend hundreds of hours rewriting code that’s already been developed for that purpose.  Either way, you will still have plenty of ExpressionEngine proprietary code.

    Think of it this way.  We know what you’re asking, trying to accomplish, and why.  And both experienced users and the creators of the application are telling you it is a bad idea, will be more difficult than it’s worth, will possibly be damaging.  Should that not be a sufficient answer to the question?

  • #11 / Aug 21, 2008 6:20pm

    turnstyle

    47 posts

    Hi Derek, I really mean no disrepect—perhaps I’m not being clear and/or I simply don’t know EE well enough to ask with sufficiently specific language.

    Also, I’m happy to use EE’s control panel & schema—but I happen to have a few reasons to consider an alternative way to render the content (fwiw, another EE creator told me that this approach would work—yes, I would lose the ability to edit the template via EE, but that otherwise it should work).

    Just in case I’ve failed to exaplin, please bear with me, and let me try again—I would still have templates within EE, but rather than having them mostly filled with HTML with some EE markup, for us it could be beneficial for the template to instead call an included PHP function, and pass values provided through the EE markup to the included PHP functions.

    I don’t really understand why this would require that I spend hundreds of hours rewriting code, or that it would possibly be damaging.

  • #12 / Aug 21, 2008 6:28pm

    Derek Jones

    7561 posts

    I don’t really understand why this would require that I spend hundreds of hours rewriting code, or that it would possibly be damaging.

    That’s the “or” portion of my statement.  The other side was “you’re either going to have to use tags anyway”, with this being key:

    and pass values provided though the EE

    EE only provides values via its tags in the template.  You are adding processing overhead if you are running those tags to get some sort of formatted output to pass to other external PHP functions.  So you’re still running the full template engine, plus your own custom PHP.  The damaging part comes into play when you start bypassing EE’s native input and output mechanisms, as indicated in the last paragraph of my linked post above.

  • #13 / Aug 21, 2008 6:38pm

    turnstyle

    47 posts

    Thank you for that—would it be cool if my intention were to pass unformatted data to the PHP functions?

    Again, I know that this approach isn’t common—and I know that people *love* EE’s templating system—heck, I love it—it’s just that, in this case, there are advantages to the approach I’m asking about.

    Thanks again! (and very sincerely!)

  • #14 / Aug 21, 2008 6:44pm

    Derek Jones

    7561 posts

    I don’t think you’re quite understanding, turnstyle.

    would it be cool if my intention were to pass unformatted data to the PHP functions?

    How do you propose to do that?

  • #15 / Aug 21, 2008 7:06pm

    turnstyle

    47 posts

    Hey Derek (fwiw, I’m Scott),

    You’re absolutely right—this is my first EE project, and so I’m working with one of your Professional Network developers to help make it happen.

    So, let me see if I can now coax him to step into this thorny thread! 😊

    -Scott

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

ExpressionEngine News!

#eecms, #events, #releases