Log in

View Full Version : use of php in header template


kjhkjh
09-07-2007, 04:58 AM
any help appreciated.

I've got a chunk of php code that looks up values from a table on the db and displays a banner image based on the forum that the code is being shown on. (in the table there are entries for image src, banner link, image alt text, image title text)

I have got this code to work on a new php page that I uploaded to the server (well I got the displaying of a banner from the table - but at this point I didn't have the conditionals of which forum, because it was a php file separate to the forum.)


When I paste this code (and try different edits) into the 'header' template the banners aren't appearing and not only that but often when I make the changes in the header template inside the admincp, i'm told:

The following error occurred when attempting to evaluate this template:

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/domain1/public_html/domain2/forums/includes/adminfunctions_template.php(3596) : eval()'d code on line 29

This is likely caused by a malformed conditional statement. It is highly recommended that you fix this error before continuing, but you may continue as-is if you wish.

I can't figure out whats wrong but only have limited php knowledge.

When I edit the header template with conditionals and simple html links, titles, alts etc, then it works. And different forums show me different banners.

But I really need each of the
image url
image hyperlink
image alt text
image title text
...to be variables sourced from a mysql table that I have created


Can anyone help me with this?

I think that it is because the 'header template' doesn't like to deal with external php code in there.

Is there a way that I can make this work?

Thanks in advance

Marco van Herwaarden
09-07-2007, 07:51 AM
Templates are HTML and you can not use PHP code in them.

Create a plugin with your PHP code and asign the output to a variable that can be used in your template.

kjhkjh
09-07-2007, 11:17 AM
Thanks Marco.

Can you point me in the direction of how to make a plugin?

(I can't seem to find any thread about it. Is it easy to do? I have all my php ready and what you said above seems easy... just no idea where to start :))

http://www.vbulletin.com/docs/html/main/templates_externalfiles

I think I can figure it out from here - does look pretty easy :)