PDA

View Full Version : A question about programatically changing templates at runtime


AfterWorldForum
09-16-2009, 06:50 AM
Hi,

Recently, I downloaded and tested the CYB Donate mod, which will add an item called DONATE to the navbar. However, I was not really satisfied with the location of it (right next to the FAQ), and started looking for a less obtrusive spot to insert it.

Initially I figured I'd try positioning it directly left from the Log Out option, but gave up on that idea after quite some failures.

I then decided I'd instead add it to my footer, and eventually, after quite a bit of trying, I managed to position it at the very right, next to the "top" link. I have a question to satisfy my curiosity, though.

The link plugin-item (or object, not sure about the proper term) uses a str_replace function to change the template, like so:

$vbulletin->templatecache['footer'] = str_replace('$vbphrase[top]</a>','$vbphrase[top]</a> - $cyb_paypal_donate_link',$vbulletin->templatecache['footer']);

Note this is not the original code, but my customized version thereof. My question is: I also tried something along the lines of the code below, which did not work. Why does the code above do the trick, but does the code below fail?

$vbulletin->templatecache['footer'] = str_replace('<a href="#top" onclick="self.scrollTo(0, 0); return false;">$vbphrase[top]</a>' , $cyb_paypal_donate_link -
<a href="#top" onclick="self.scrollTo(0, 0); return false;">$vbphrase[top]</a>' , $vbulletin->templatecache['footer']);

I have two possible explanations, but would like other input, so if the need arises again in the future, I can actually get things right the first time :)

1) The str_replace function only supports a certain amount of characters (Pretty sure this is not the case, as I also tried replacing parts of the code above, but to no avail)
2) It's due to there being HTML tags in the code, which at the time of the replace happening have already been parsed.

My money is on option 2, but a second opinion would be greatly appreciated, along with maybe some tips and hints on how to fiind out more.

Cheers.

Peter

Lynne
09-16-2009, 02:48 PM
It's not 1), but it may be because you are using $vbphrase in there and the phrase may actually already be parsed at that time.