PDA

View Full Version : problems: str_replace for template edits and conditionals


mfyvie
06-01-2007, 10:11 AM
I'm using str_replace to try and get a plugin to modify a template. This in itself is not a problem, but as soon as I add in a conditional, it doesn't seem to be parsed when the template is run.

Here's what I'm trying to do:

$disabled_add = ' $disabled /><if condition=\"$disabled==\"disabled\"\"><span style=\"color: grey\">$vbphrase[avatar_taken]</span><else />$avatar[title]</if>';

$vbulletin->templatecache['modifyavatarbit'] = str_replace(' />$avatar[title]', $disabled_add, $vbulletin->templatecache['modifyavatarbit']);

note that I had to use a backslash before the double quotes otherwise all sorts of php errors were being produced.

When we look at the output we see that the conditional statements, instead of being evaluated are finding their way into the HTML output:

<input type="radio" name="avatarid" value="1880" id="rb_avatarid_1880" /><if condition="=="disabled""><span style="color: grey">Taken</span><else />Sup29</if> </label>

If I insert the changes directly into the template (without the backslash quoting of course) then the conditionals work as expected.

My guess is that conditionals inserted via str_replace aren't being evaluated correctly. Is this a bug, or does anyone know of any work-arounds. I've tried to find other mods that do this but so far haven't found any. A search of this forum and google has also proved fruitless.

Any help would be appreciated

Dismounted
06-01-2007, 10:26 AM
You can't base them off conditionals, as they change into ((CONDITION) ? true : false).

mfyvie
06-01-2007, 10:40 AM
You can't base them off conditionals, as they change into ((CONDITION) ? true : false).

Any ideas for a work-around? Is it possible to maybe include the extra code in a different template, and then simply call that template from inside the template (and make that insertion via str_replace)?

Sorry, kind of muddling my way through this mod, but am learning a lot as I go

mfyvie
07-05-2007, 08:24 AM
You can't base them off conditionals, as they change into ((CONDITION) ? true : false).

Actually, you can base them off conditionals, you just have to know the correct format, then it is possible.

It's taken me ages, but I figured it all out and wrote it up in a tutorial (or rather series of tutorials) here:

https://vborg.vbsupport.ru/showthread.php?t=151332