tags:

views:

63

answers:

2

Hello! I have the following dilemma. I have a complex CMS, and this CMS is to be themed by a graphic designer. The templates are plain HTML, with several nested inclusions. I'd like to make it easier for the designer to locate the file to be modified, by looking at the HTML of the page.

What I thought in the first place was to build something stupid like this:

function customInclude($what) { 
  print("<!-- Including $what -->");
  include($what);
  print("<!-- End of $what -->");
}

but, guess what? Variables obviously come out of scope in the included file :-) I can't declare them as global or as parameters, as I don't know how they are called and how many are there.

Is there any possibility to implement some kind of "macro expansion" in PHP? An alternative way to call it: I'd like to modify each call of the modify function, in an aspect-oriented style.

I have thought about eval(), is it the only way? Will it have a big impact on performance?

A: 

You should definitely use objects, namespaces and MVC model. Otherwise there is no pure and clean solution to your problem. And please, don't use eval, it's evil.

Mikulas Dite
This was not an answer, and moreover it was not helpful at all. Use comments next time. Anyway, you are just repeating what others say without supporting it with anything. By the way, this is quite a complex MVC implementation, but this question is of entirely different nature. In the eyes of a graphic designer, the architecture is just not relevant: she just wants to have quick access to the specific file on the disk, without thinking about apache redirections, routes, controllers, views, parameters, ajax calls and so forth. The output is a bit too complex for just looking at the URL.
Palantir
Are you serious? When no solution exists, it's still an answer. However, I was not talking about anybody else - it's you who will have problems without OOP. It's your call, but then don't try to bypass obvious language behavior with eval. Moreover, I can hardly see anybody else answering here. The MVC architecture does exactly what you'd like - it splits templates and code where each belongs, so the designer never has to see the code and vice versa.
Mikulas Dite
Please, do read more carefully. I have told you that I am using OOP and MVC. I have a series of views (say: node/edit.tpl.php, node/index.tpl.php, etc...), then a bunch of partial views, which in turn call other partial views. I wanted to help the designer to quickly locate the view file. Do you really think this is absurd? The other "clean" option is to put at the top of each view its name, and close it at the bottom...
Palantir
+1  A: 

Not sure if I entirely understand the question, but if you're just trying to make life easier for the designer by showing them the underlying filename of the included file, then you can probably just use this within the template files:

echo '<!-- Start of '.__FILE__.' -->';
....content... 
echo '<!-- End of '.__FILE__.' -->';

__FILE__ is just one of several Magic Constants.

Also there's the get_included_files() function that returns an array of all the included files, which might be of use (you could output a list of all the included files with 'tpl' in their name for example).

Vex
The first is in fact what I am doing now :) Unfortunately, it forces me to put a header and a footer in each template, which is a bit awkward. Get_included_files seems interesting, I could output that at the end of the source. It's still not optimal, because the nesting is not shown.
Palantir