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.

Putting simple test PHP 'hello world' in template results in blank page (output) or error message (input).

August 26, 2010 3:45am

Subscribe [3]
  • #1 / Aug 26, 2010 3:45am

    Susan

    81 posts

    Setup:
    EE 1.6.8
    Build 20100121
    Hosting Environment: MAMP (PHP 5.2.11), VirtualHostX


    I’m working on a use of PHP in template to do a simple calculation. Result when viewing rendered template: Blank.
    Tossed out the calculation PHP code and attempted to do a simple hello world in PHP. Result: blank.

    Template Preferences for news/view_debug (the path and template):
    Allow PHP: Yes
    PHP Parsing Stage: Output

    <?php  echo "hello, world!"; ?>

    When I use Parsing PHP on output, the page is blank.

    When I change it to PHP on input (just to test; for this situation I’ll want to do PHP on output), this is the error message I get:
    Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /Volumes/KTHXBAI/vhosts/mysitename.dev/system/core/core.functions.php(634) : eval()‘d code on line 35

    This is line 35 of my template, the most recent location where I put the hello world (it’s inside of exp:weblog:entries tag pair)

    <h2 class="title"><?php  echo "hello, world!"; ?> <a href="http://{title_permalink=news/view}" title="Perm…"> {title} </a></h2>

    Moved it outside exp:weblog:entries.
    Cleared all caches.
    debugging on, debugging off.
    No joy.

    Clues and assists for this baffling situation?

    . . . . . . .

    Background and where I’m eventually going: Thanks to LOW’s EECI2010 SF PHP and templates session, I feel brave enough to give PHP in templates a go. Working toward eventually putting together Matrix, Imgsizer (and, we hope, LG Replace) in order to do AJP’s wonderful image replacement trick, with the addition of re-creating the EE out-of-the-box javascript pop-up thumbnail link routine to ‘click to embiggen’.

    Why I wish to use PHP: Do a very simple calculation to take imgsizer’s { width } and { height } values and add 15 in order to mimic EE’s out of the box pop-up thumbnail link code. (Prefer image showing up in sep window, tho I could do Lightbox instead if this all fails.) Want to use matrix+imgsizer to create what’s viewed on the page, and adjust its size either by changing img-width settings in the appropriate Matrix and/or force a size change in my template. This is step 0.5 before doing a site redesign where column widths and image widths may change with the next rev of the site.

  • #2 / Aug 26, 2010 3:47pm

    Ingmar

    29245 posts

    Can you try just PHP in a template of its own? No other code at all. Does that work? Also, is there a particular reason for you to work with 1.6.8? I’d suggest using the latest version and build for your site.

  • #3 / Aug 26, 2010 5:54pm

    Susan

    81 posts

    In template on its own (with same preference settings, i.e., allow PHP/output), the simple hello world statement DOES work.

    Also, I tried a similar thing on the live server version of the site. Engine Hosting, PHP 5. On its own, all by itself, it works. Same with a different, simpler template. (haven’t tried the original news/view_debug on the live server, because I’m working on local MAMP server to Do Something New and I’m Not Ready Yet)

    Other things I have done:

    On both MAMP and Live server, duplicated a working template news/view -> news/view_viewphptest, and added the one bit of PHP Hello World to it. (template prefs: yes PHP, Output)
    Both of those work.

    So I’m guessing now that there’s something else with the code called upon in my news/view_debug templates. Will go back, examine, and then prolly post more of the template itself in a later post here.

    (As to why 1.6.8, inertia. My old upgraded time expired in Feb, and I was planning on upgrading when I was going to get ready to switch the site to 2.1. Which is Not Yet.)

  • #4 / Aug 26, 2010 7:17pm

    Susan

    81 posts

    found it. (thank you, BBEdit’s Show Invisibles and Show Spaces)

    Turns out that inside the php statement, somehow I’d either copied/pasted or typed option-space instead of space after the opening ?php So EE was choking on that. In this example, second line, I put an asterisk * where the option-space was.

    <?php echo "hello, world"; ?>
    <?php*echo "hello, world"; ?>

    Hooray for BBEdit, which represents option-space as a grayed bullet, rather than the little diamond shape thingum. As soon as I typed the space where it shoulda been in the template, voila! it worked!

    Cue both facepalm and happy dance.

  • #5 / Aug 26, 2010 7:23pm

    Susan

    81 posts

    p.s. serves me right for cutting and pasting the same bit of code here and there in the template. Placement didn’t matter, that dang character did.

  • #6 / Aug 26, 2010 7:27pm

    Sue Crocker

    26054 posts

    Glad you were able to figure out what the problem was. Don’t hesitate to post again as needed.

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

ExpressionEngine News!

#eecms, #events, #releases