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.

Newbie asks - template within a template to use php?

November 07, 2011 2:27pm

Subscribe [3]
  • #1 / Nov 07, 2011 2:27pm

    dagnew

    5 posts

    I’m administering a site that I had built ‘by hand’ with html, css & some simple php, but which has been re-built by an EE developer team. I’m new to EE and reality hasn’t yet allowed me the luxury of ‘reading the manual’. I’ve searched this forum regarding my question, but didn’t find much. So, with apologies for my very limited understanding…

    I believe that I need to use php within a div on the home page to display some info parsed from xml. I don’t want this info to display anywhere else on the site. The home page uses a template named site/index, and quite a number of other pages use this template as well. I enabled php for that template, but any php I put into the source for the home page (cclighthouseschool.org) got displayed by EE as messed-with text. I eventually figured out that I could put php in the template, but not in the source for the page based upon that template.

    Do I need to base the home page on a new template that no other page uses? Would nesting templates be helpful? Is there a simpler way?

    Thanks in advance for any tips!

  • #2 / Nov 08, 2011 4:57pm

    Kevin Smith

    4784 posts

    Hi dagnew,

    Welcome to the community!

    Could you give us some more detail for how the templates for different pages are set up? I’m trying to understand how the site/index template is being used for more than just the site index. That will play a big part in the solution we’re able to come up with for you.

    You may also want to look at one of the many XML-related add-ons that Devot:ee has listed. While using PHP is possible in templates, it’s best practice to keep it as a last resort.

  • #3 / Feb 16, 2012 3:15pm

    dagnew

    5 posts

    I apologize for posting and ignoring! I actually solved my problem, and somehow assumed that I was the only one who thought it was a problem (this required ignoring a couple of PMs as well, which I seem to be too good at). Again, sorry!

    The template (which ‘allows php’) calls another template {embed="_globals/top"} which in turn has html for doctype, head and (this in response to the PMs I received)

    <link rel="stylesheet" href="/css/style.css?v=2">

    The template then has php:

    <?php
     include('/homepages/39/d1234567/htdocs/foo/lib/foo.inc');
     customFunction("boo");

    this all works just fine. 😊

  • #4 / Feb 16, 2012 3:24pm

    dagnew

    5 posts

    Could you give us some more detail for how the templates for different pages are set up? I’m trying to understand how the site/index template is being used for more than just the site index.

    I’m satisfied with the solution I came up with (unless there’s some reason that it’s a BAD IDEA). As for the site/index template’s use, it is the home page of the site that I wanted to call php from. The result of this effort is the ‘Dates to Note’ section at the right (which parses a Google Calendar XML feed) on this page. Thanks for your reply, I’m sorry for my VERY delayed response! - David

  • #5 / Feb 16, 2012 3:51pm

    Ian Young

    200 posts

    PHP in templates is honoured on a per-template basis so if you have one template (a child) nested inside another template (the parent) then only the child template needs to have PHP enabled.

    In your case it sounds like the PHP is actually in the index.php template however but if you wanted to make things a little safer then you can extract that PHP section out to it’s own template, enable PHP for that template only and then embed it inside your index.php template. Then you shouldn’t need PHP to be enabled in your index.php template anymore.

    This is down to preference though but it’s generally always better to keep things locked down.

  • #6 / Feb 20, 2012 3:49pm

    Shane Eckert

    7174 posts

    Hello dagnew,

    I am glad to hear that you were able to get this sorted out. No worries on taking awhile to return to the issue. As long as you are happy, we are happy.

    Cheers,

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

ExpressionEngine News!

#eecms, #events, #releases