Page 1 of 1

Problem with including PHP in template

Posted: Thu May 24, 2007 3:15 am
by panther_sn
Hi I am trying to findout how I would go about including PHP into my template.

I have a file called browser_detect.php

Code: Select all

<?php
if (strstr($_SERVER["HTTP_USER_AGENT"], "MSIE")) {
?>
<center>You seem to be using a version of Internet Explorer. For a safer browsing experience, please consider either the Google Pack, or just FireFox itself:<br/>
<i>
<__script__ type="text/javascript"><!--
google_ad_client = "pub-xxxxxxxxxxxx";
google_ad_width = 180;
google_ad_height = 60;
google_ad_format = "180x60_as_rimg";
google_cpa_choice = "xxxxxxxxxxxxxxxxxxxx";
google_ad_channel = "";
//-->
</__script>
<__script__ type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</__script>
</i> <i>
<__script__ type="text/javascript"><!--
google_ad_client = "pub-xxxxxxxxxxxxxxxxxxxx";
google_ad_width = 180;
google_ad_height = 60;
google_ad_format = "180x60_as_rimg";
google_cpa_choice = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
google_ad_channel = "";
//-->
</__script>
<__script__ type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</__script>

</i>
</center>
<?php
} else {
?>

<?php
}
?>
browser_detect.php Works beautifully by itself, BUT I really can't figure out how to include it into CMSms and I tried just placing the code into template BUT nope nothing showed Up.

so if some1 can help me trying to figure out how to include it on my Home page in CMSms ?

Sorry new to PHP soooo having major some probs

Re: Problem with including PHP in template

Posted: Sat May 26, 2007 12:14 am
by panther_sn
Sorry to Bump this but wondering, if any1 has any idea how I would do this?

Re: Problem with including PHP in template

Posted: Sat May 26, 2007 12:31 am
by Anastasis
panther_sn wrote: Sorry to Bump this but wondering, if any1 has any idea how I would do this?
You could include it directly in your template and just wrap it in {literal} tags:

{literal}
--- your php code ---
{/literal}

or for a cleaner and more reproducible approach for other templates that you may want to use it in then put the lot in a global content block complete with the literal begin and end tags and just add a call into your template:

{global_content name='browser_detect'}

Re: Problem with including PHP in template

Posted: Sun May 27, 2007 2:33 pm
by myshko
You could also build a user defined tag, which parses php code directly (no need for literal tags) and simply call it using curly brackets.

So if you called your tag 'browser_detect' you'd just add {browser_detect} to your template.

User defined are more powerful than content blocks as they can use variables from other CMSMS modules and be passed variables from the tag in your template.

D

Re: Problem with including PHP in template

Posted: Tue Jun 26, 2007 11:42 pm
by iano
under-radar wrote: User defined are more powerful than content blocks as they can use variables from other CMSMS modules and be passed variables from the tag in your template.
This works great; except I'm not sure how to pass variables from my tag to the template.  I created a drop-down list of news categories with a user tag.  Now I want to pass the selected value to the template so it filters the news items based on the selected category.

          {news_category_filter}
          {cms_module module='news' category=$category number='10'}

$category is the selected value from the code in the user tag.  How do I pass it into the news module?

Cheers,

Ian

Re: Problem with including PHP in template

Posted: Wed Jun 27, 2007 8:17 am
by cyberman
Hi Ian,

to the first - I think $category is not a good idea for a variable name cause this one it's IMHO used inside news module.

But the answer to your request is the Smarty capture function. Try something like this

Code: Select all

          {capture name=dropdownlist assign=myCategoryList}{news_category_filter}{/capture}
          {cms_module module='news' category=$myCategoryList number='10'}
http://smarty.php.net/manual/en/languag ... on.capture

But maybe you should make a look at news modules browsecat parameter. It outputs a news modules category list too. With a little modification of browsecat.tpl you will get a dropdownlist  ;) ...

Re: Problem with including PHP in template

Posted: Wed Jun 27, 2007 8:44 pm
by iano
Thanks for the reply.  However, my UDT outputs the list control so the user can select a value.  I just want the selected value.  If I make this a return value in the UDT, then try capture, the control disappears along with the return value.  Suggestions?