PDA

View Full Version : Widget PHP code in Smarty templates - ARRRGH!


PAdams
05-02-08, 04:21
:confused: Please help I've been trying all day to get this to work.

I'm trying to place a widget beneath the hotpics in my home page.

I created a php file called valentines.php

<?php
include ('http://www.awin1.com/wshow.php?inc=1&s=92930');
?>


and then tried to place that into my index.tpl template. Like this

{include file="elements`$DIRECTORY_SEPARATOR`valentines.php"}

I tried many, many connotations with all sorts of crazy things happening (including trying it in the index.php in which case it appeared in the header or below the footer.)

Please put me out of my misery, someone help, please.


http://www.todaynet.co.uk/stores/uk/index.php

PAdams.

Andy
07-02-08, 14:31
Personally I would have done it differently.
I usually prefer to use file_get_contents(); function, strip out all the usual crap that comes in network widgets and create variables out of whats left.
You could then assign these variables to smarty and kick them out as usual. this gives the added benifit of the content being ACTUAL content on your page, rather than just a script call.

However, the very easy approach would be to simply add the following where you want it in your smarty template:

(script src="http://www.awin1.com/wshow.php?inc=1&s=92930" type="javascript/text" language="javascript")(/script)


change () to <>

I think, anyway. Never used affwin widgets

hope this helps

Andy
12-02-08, 14:10
Did this work for you P?
If so, let us know then this can become a resource for anyone who has similar problems.

Share the love man! Share the love!

PAdams
21-02-08, 20:31
Hi Andy,

Thanks for being the only person to reply.

I didn't want to use javascript as the included content isn't visible to search engines, one of the prime reasons for including it in the first place, ahem!

I did find the solution though.

I call a 'feed template', which contains a php feed url, which contains the include feed link. This may seem clumsy but the 'myfeed' file contains dozens of feeds for different pages on my site, so they are all managable in one place.




{include file="elements`$DIRECTORY_SEPARATOR`carp_feed.tpl"}

the php file...
{php}
include_once ("http://www.todaynet.co.uk/myfeed_rss.php");
{/php}

the feed url in 'myfeed'...
<?php
...Show("http://images.apple.com/main/rss/hotnews/hotnews.rss");
?>



It works, look here..
http://www.todaynet.co.uk/stores/uk/index.php

Andy
22-02-08, 16:00
Ah, you dont want the javascript, but you want the content of the javascript eh?

well, if you're fairly competant with PHp try mixing these functions:

file_get_contents (to get the generated contents of the javascript)
explode (to find a beginning and an end to what you want to use)
str_replace (to strip out any "document.write()", or simply to replace colours,links etc. A good way to get rid of the digital window link!)

As I mentioned above, this method can be used to create variables allowing you to do pretty much anything with the widget. The only way it wouldn't work is if AffWin didn't allow file_get_contents from their servers, which they do, so it's ok. (And they better keep it that way!!)