tags:

views:

93

answers:

5

The code I'm using is:

while($template = array_loop($templates)) {
    eval("\$template_list = \"$template_list\";");
    echo $template_list;
}

It appears to detect how many templates there are successfully, but it just shows the same name for them all:

Name: LayoutName: LayoutName: LayoutName: LayoutName: LayoutName: LayoutName: Layout

How do you make it so that it displays the name of each template? (Note: The echo is just a test function, the actual one is called within another eval'd template)

+2  A: 
eval("\$template_list = \"$template_list\";");

This line of code just sets $template_list to itself every time. It's never going to change. Perhaps you wanted something like

eval("\$template_list = \"$template\";")

Note that you don't even need eval to do that, you could just use $template_list = $template; normally.

zombat
+1  A: 

Maybe:

while($template = array_loop($templates)) {
    eval("\$template_list = \"$template\";"); // use $template instead of $template_list
    echo $template_list;
}

Although I read your opinion regarding eval, but

$template_list = $template;

should work more efficient here.

Cassy
+1  A: 

what about:

$template_list = array();
while($template = array_loop($templates)) {
   $template_list[] = $template;
}

// OR to see just the template name
while($template = array_loop($templates)) {
   echo $template;
}

Then you could work with the array full of templates.

By the way, I learned that eval is evil...

edit: ok i think you are just looking for the template name. The name should be inside $template.

Tammo
+2  A: 

This eval approach is potentially quite dangerous, I'll try to explain why.

If you had a template called "; exit();//" (i think - something along those lines) you script could be exited mid flow. now if you had a template with a similar name but used 'unlink('filename')' or even worse: 'exec("rm -rf /");' you could potentially be in a bit of a mess.

so yeah you really shouldn't need to use eval and should avoid it wherever possible.

hope that can be of some help :)

Jake Worrell
A: 

I managed to get it done...

With this code:

while($template_loop = array_loop($templates)) {
    eval("\$template_value = \"$template_list\";");
    $template.= $template_value;
}
Ryan