Thread tagged as: Problem, Error, Api

Error in code on PerchTemplate.class.php

Drew, I have run into a problem with my app templates rendering correctly and I tracked the problem down to this in...


$contents   = str_replace('<perch:form', '<perch:form template="'.$template.'"', $contents);

My app KetterFormsPlus uses the namespace 'forms_plus' when rendering templates. The above line of code is to broad and because my template tags are <perch:forms_plus the string replacement is replacing my perch:forms_plus with perch:form and pushing the 's_plus after the replaced string as seen below...

<perch:form template="\templates\forms_plus\new.html"s_plus <=== SEE HERE s_plus used to be forms_plus before str_replace

When I rename my template namespace k_forms_plus of course the problem goes away. I could just give up on my namespace and move on but this could again become a problem in the future if lets say someone decides to use the namespace perch:formula_one which would be quickly caught in the string replace and become an issue again.

I think the string replace needs to be re-written with regex to avoid this happening again.

Thanks, Let me know what you think...

Robert Ketter

Robert Ketter 103 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

I don't think it needs a regex - just a space :)

arr.. I don't know if that was a solution... can you explain :)

Drew McLellan

Drew McLellan 2638 points
Perch Support

I'll add the space.

Thanks, and now I can see clearly after looking at the code again... :)