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.

Embed custom PHP functions across templates

May 26, 2012 4:02am

Subscribe [2]
  • #1 / May 26, 2012 4:02am

    Scotta

    136 posts

    Hello,

    I need to use PHP in several templates (mostly add/remove variables from the PHP session), and I’m looking for the right way to embed a set of php functions, that I could re-use across all these templates.

    I could try to make a plugin, but I’m afraid with parsing order issues, and I think I’d rather use the functions in php, not in template tags .

    Obviously, I don’t want to mess things up with EE’s built in functions, so I need your good advice !

    Cheers.
    L.

  • #2 / May 27, 2012 7:36am

    adrake9

    57 posts

    In cases where I’m ok using php in templates I just do an include to a custom functions file at the top of my template. You will have to use the full server path ( something like var/www/yoursite/lib/mycode/custom-functions.php).

    More recently I’ve been writing plugins to accomplish a lot of the php stuff that I need.

    Speaking of plugins…. maybe this one?

    http://www.putyourlightson.net/session-variables-plugin

  • #3 / May 27, 2012 7:41am

    Scotta

    136 posts

    Hi adrake9,

    I’m well aware of the session variables plugin, but it’s not sufficient for what I need.
    I was not using the full server path, and thought the error was related to EE not allowing me to do that !
    It’s working now.

    BTW, I should write a plugin, but it would be a headache to create a plugin that would suit each page where I need it, and I’m in a rush.

    Thanks !

     

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

ExpressionEngine News!

#eecms, #events, #releases