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.

Using PHP variables in entries (or alternative)

December 07, 2011 4:42am

Subscribe [4]
  • #1 / Dec 07, 2011 4:42am

    TheBlackHole

    72 posts

    Hi all,

    There is an XML feed which I am extracting variables from using php.

    So have set up the variables and then I can just print the stored php variable…

    <?php print $package; ?>

    This is fine on templates, but I need to output the code in an entry text field.

    All my efforts so far have failed so any help will be appreciated. I know there used to be an allow php plugin but I can’t find a version for EE2.

    If anyone has an alternative/better idea let me know : )

    Many thanks

    p.s Regrettably, this post is a duplicate of one I posted 2 weeks ago in the community support forum, I PM’d a moderator to ask if it was in the correct forum and to move it if not but nothing has happened and this is now quite urgent. If any mods read this could you please delete the original post.

     

  • #2 / Dec 07, 2011 10:26am

    glenndavisgroup

    436 posts

    Hi TheBlackHole,

    Can you post your code or parts of it? Also, what is the exact version of your EE installation?

    Mike

  • #3 / Dec 07, 2011 10:51am

    TheBlackHole

    72 posts

    Sure…

    EE v2.2.2 - Build: date 20110801

    Set variables up…

    <?php
    
    // fetch the xml 
    $dom = new DOMDocument;
    $dom->preserveWhiteSpace = false;
    $dom->load("http://ageuk-basket.uat.theblackhole.co.uk/compare-plans-xml.aspx"); 
    
    // save to html variable
    $raw = $dom->saveXML();
    
    // xpath query to get price nodes
    $xp = new DOMXPath($dom);
    $nodes = $xp->query('//tr[@class="price"]/td');
    
    // setup variables
    $package1 = $nodes->item(1)->nodeValue;
    $package2 = $nodes->item(2)->nodeValue;
    $package3 = $nodes->item(3)->nodeValue;
    
    ?>

    Show variables

    <?php print $package1; ?>
    <?php print $package2; ?>
    <?php print $package3; ?>

    So basically I need those variables to be available for use in an XHTML text field in the publish page.

    Many thanks

  • #4 / Dec 08, 2011 4:16am

    John Henry Donovan

    12339 posts

    Hi TheBlackHole,

    If you need these variables to be available in the Publish page of the control panel then I would suggest creating an add-on.

    The add-on would be two parts and firstly make that call to the XML and then make those package variables available with some work as {package_1},{package_2} and {package_3} to be used in custom fields in your entry form

    We have an overview of EE Add-on development here


    Does that help?

  • #5 / Dec 08, 2011 4:34am

    TheBlackHole

    72 posts

    Hi John,

    That sounds like a great idea but unfortunately I have no php knowledge. This code was passed on from a now unavailable developer.

    Do you see any other options?

    Cheers

  • #6 / Dec 08, 2011 4:43am

    John Henry Donovan

    12339 posts

    Gotcha,

    I vaguely remember there being an add-on that allowed PHP within a custom field on Publish page but couldn’t find it on initial search on devot-ee.com. You might have more luck though. You could also ask the #eecms community on twitter and somebody might be able to help you out

  • #7 / Dec 08, 2011 4:49am

    TheBlackHole

    72 posts

    I searched and failed with regards to finding an EE2 version of that plugin. So are you saying there isn’t a native way to achieve this? Remember I don’t necessarily need to use this exact method. I just need to get these variables midst text.

    I hope there is some solution : /

  • #8 / Dec 08, 2011 4:50am

    John Henry Donovan

    12339 posts

    To confirm. There is no native way to do this unfortunately

  • #9 / Dec 08, 2011 4:53am

    TheBlackHole

    72 posts

    Ah, bummer.

    Hopefully someone will chime in and save the day ; )

    Cheers John

  • #10 / Dec 08, 2011 7:47pm

    Sean C. Smith

    3818 posts

    Hi TheBlackHole,

    I can move this thread to community support for you if you would like since there is no native way to do that in EE.

    Sean

  • #11 / Dec 09, 2011 4:48am

    TheBlackHole

    72 posts

    You can do Sean, if you do that would you please remove the duplicate post (mentioned in my original message)

    Cheers

  • #12 / Dec 09, 2011 4:39pm

    Sean C. Smith

    3818 posts

    Hi, I’ve moved the thread and will go find your other thread.

    Sean

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

ExpressionEngine News!

#eecms, #events, #releases