Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #3556

Re: execute php in template

From Gregor Kofler <usenet@gregorkofler.com>
Newsgroups comp.lang.php
Subject Re: execute php in template
Date 2011-10-24 01:20 +0200
Organization A noiseless patient Spider
Message-ID <j827f9$dke$1@dont-email.me> (permalink)
References <a7a128ef-7730-4b2b-be6c-5fda82c287cf@31g2000prp.googlegroups.com> <j81vf4$heo$1@news.albasani.net> <b0d7f670-0c74-4486-b74e-8231778d305c@x16g2000prd.googlegroups.com>

Show all headers | View raw


Am 2011-10-24 00:43, cerr meinte:
> On Oct 23, 2:03 pm, The Natural Philosopher <t...@invalid.invalid>
> wrote:
>> cerr wrote:
>>> hi There,
>>
>>> I have a page that i assemble with a graphics template and a content
>>> file in my index.php. Kinda like:
>>> <?
>>> $template = file_get_contents($tmpl_path);
>>> $content = file_get_contents($cont_path);
>>> and in template, there's a marker where to insert the content:
>>> $page = str_replace("[CONTENT]",$content,$template);
>>> echo $page.
>>
>>> This works well so far, but if I wanna use php in my template, it
>>> doesn't get executed by file_get_contents(). How can I load this file
>>> and execute php within it? Also, I would like to reuse ($_GET)
>>> variables i have in index.php. Do I need to forward them to my
>>> template by a regular get url or will i just be able to reuse the
>>> variables straight?
>>> Thanks for help in this matter!
>>
>> try
>> include("/path/to/my_template");
>>
> 
> Thanks to both for the replies, I have not tried exec or passthru but
> include e.g. won't return me anything, it'll just execute the template
> right there instead of returning me a string that i'll be able to
> modify (to insert the content)...

Buffer the content (ob_start() and accompanying functions) and work with
the buffer content, flush buffer once you are done.

Gregor


-- 
http://vxweb.net

Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

execute php in template cerr <ron.eggler@gmail.com> - 2011-10-23 12:47 -0700
  Re: execute php in template Jerry Stuckle <jstucklex@attglobal.net> - 2011-10-23 16:29 -0400
  Re: execute php in template The Natural Philosopher <tnp@invalid.invalid> - 2011-10-23 22:03 +0100
    Re: execute php in template cerr <ron.eggler@gmail.com> - 2011-10-23 15:43 -0700
      Re: execute php in template Gregor Kofler <usenet@gregorkofler.com> - 2011-10-24 01:20 +0200
      Re: execute php in template Jerry Stuckle <jstucklex@attglobal.net> - 2011-10-23 19:38 -0400
        Re: execute php in template Hans Olo <doctor@vaderlishious.com> - 2011-10-23 20:37 -0500
          Re: execute php in template Jerry Stuckle <jstucklex@attglobal.net> - 2011-10-23 22:30 -0400
            Re: execute php in template Hans Olo <doctor@vaderlishious.com> - 2011-10-24 07:39 -0500
              Re: execute php in template Jerry Stuckle <jstucklex@attglobal.net> - 2011-10-24 09:16 -0400
  Re: execute php in template Goran <goran@nospam.com> - 2011-10-24 09:02 +0200

csiph-web