Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing PHP variables inside of here documents inside of functions inside of a class
    primarykey
    data
    text
    <p>If the title hasn't scared you away yet, read on. I'm working on an ExpressionEngine website and I'm editing the member templates file. All templates that relate to member interaction are stored as functions inside of a class in one single file.</p> <p>Each of these functions is a simple here document, but many of them print code with paths and terms that I don't care to use. For instance, this website will refer to logged in users as "clients" instead of "members."</p> <p>Anyway, I'm looking for a way to abstract these values so that I can change them easily for this and future projects. Right now, I'm able to print variables inside of here documents by defining them <em>within</em> each function. I would much prefer to define these values in the top of the file, before the class is defined, but I can't get the here documents to recognize these values.</p> <p>Here's an abridged example file:</p> <pre><code>&lt;?php /* I wish to define variables once in this area */ $globaluserterm = "client"; class profile_theme { //---------------------------------------- // Member Page Outer //---------------------------------------- function member_page() { $userterm = "client"; return &lt;&lt;&lt;EOF &lt;div id="{$userterm}-content"&gt; &lt;h1&gt;{$userterm} Account&lt;/h1&gt; (Note: This DOES work) &lt;h1&gt;{$globaluserterm} Account&lt;/h1&gt; (Note: This doesn't work) {include:member_manager} &lt;/div&gt; EOF; } /* END */ //------------------------------------- // Full Proile with menu //------------------------------------- function full_profile() { $userterm = "client"; return &lt;&lt;&lt; EOF &lt;div id="{$userterm}-full-profile"&gt; {include:content} &lt;/div&gt; EOF; } /* END */ } // END CLASS ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload