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.

PHP variables spanning multiple templates

August 27, 2012 7:54pm

Subscribe [4]
  • #1 / Aug 27, 2012 7:54pm

    Aaren Hofferth

    55 posts

    Is there a solution for PHP scripts that have to span multiple templates?

    For instance, template A has:

    <?php
    
    $name = "John";
    
    ?>

    And template B has:

    <?php
    
    echo $name;
    
    ?>

    Currently, it appears all PHP parses on a template bases so that this is not possible.
    I currently have functions that must execute before the page loads, but I have to be able to call variables it outputs in other templates through the site.

     

  • #2 / Aug 28, 2012 9:18am

    Rob Allen

    3114 posts

    Is this for something like logged in members? If so you can use member profile tags to pull in data, see http://ellislab.com/expressionengine/user-guide/modules/member/index.html#custom-profile-data-tag

  • #3 / Aug 30, 2012 1:31pm

    e-man

    1816 posts

    Have a look at http://devot-ee.com/add-ons/mo-variables it may be helpful. And if you need php vars to consist across templates you may consider using cookies or session vars.

  • #4 / Aug 30, 2012 8:27pm

    Aaren Hofferth

    55 posts

    I’m not doing anything with members unfortunately. I’m actually running a <?php include(”/file.php”); ?> on template A and then trying to output some data from that include in template B. I’ll take a look at mo’ variables—that may be close to what I’m looking for.

  • #5 / Oct 05, 2012 5:39pm

    shinymachine

    2 posts

    I used to do this in the path.php on EE 1.6.8 and it worked but now on EE 2.5.3 I can’t seem to get it to work. Any thoughts?


    $global_vars = array (
        “my_functions” => $_SERVER[‘DOCUMENT_ROOT’] . “/includes/inc.functions.php
      , “my_global_var” => “My Name”
      , “my_other_global_var” => “Some Data”
    )


    Then in any template I could do this:

    <? p h p

    include(’{my_functions}’);

    echo ‘{my_global_var}’;

    echo ‘{my_other_global_var}’;

    ? >

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

ExpressionEngine News!

#eecms, #events, #releases