Problem with including PHP in template

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Locked
panther_sn

Problem with including PHP in template

Post 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
panther_sn

Re: Problem with including PHP in template

Post by panther_sn »

Sorry to Bump this but wondering, if any1 has any idea how I would do this?
Anastasis

Re: Problem with including PHP in template

Post 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'}
User avatar
myshko
Forum Members
Forum Members
Posts: 102
Joined: Wed Feb 07, 2007 2:36 pm

Re: Problem with including PHP in template

Post 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
iano
New Member
New Member
Posts: 4
Joined: Wed May 17, 2006 7:36 pm

Re: Problem with including PHP in template

Post 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
cyberman

Re: Problem with including PHP in template

Post 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  ;) ...
iano
New Member
New Member
Posts: 4
Joined: Wed May 17, 2006 7:36 pm

Re: Problem with including PHP in template

Post 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?
Locked

Return to “CMSMS Core”