Inserting PhP scripts in a template

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
Anduril

Inserting PhP scripts in a template

Post by Anduril »

I am trying to create a login system in my cms template, but it the PHP scripts don't seem to work when I put them in a template. Am I doing something wrong?
Anduril

Re: Inserting PhP scripts in a template

Post by Anduril »

For example:

I want the login form to show up when your not logged in and the action should sent the information to the page himself. I haven the following script, it works on a normal site, but not in a cmsms template...:

Code: Select all

<?php if(!isset($_SESSION["login"])){ ?>
<table width="140" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td class="logintabel" align="center">
        <form name="loginform" method="post" action="<?php echo($_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING']); ?>">
	Username:<br>
	<input name="loginusername" type="text"><br>
	Password:<br>
	<input name="loginpassword" type="password"><br>
	<input name="loginsubmit" type="submit" value="Login">
    </form>
	    <h3><a href="phpbb/index.php">Registreren!</a></h3></td>
  </tr>
</table>
<?php } ?>
pishkus

Re: Inserting PhP scripts in a template

Post by pishkus »

Create a User defined tag, place all your php code there, and insert into the template {your_tag_name}
Anduril

Re: Inserting PhP scripts in a template

Post by Anduril »

So I should create a user defined tag for every little piece of PHP?

Isn't there an other way? {php}{/php} or {literal}{/literal}
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: Inserting PhP scripts in a template

Post by calguy1000 »

Yes, you can use {literal}{/literal} and for complex, multi-part php stuff, that may be the better way.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Ted
Power Poster
Power Poster
Posts: 3329
Joined: Fri Jun 11, 2004 6:58 pm
Location: Fairless Hills, Pa USA

Re: Inserting PhP scripts in a template

Post by Ted »

For php code, you can use {php}{/php}.  However, in order for it to work, you need to set the allow_php_tags (I think?!? -- something close to that) value to true in config.php.
Anduril

Re: Inserting PhP scripts in a template

Post by Anduril »

OK, that's the solution:
For PHP to work in a template edit the config.php

$config['use_smarty_php_tags'] = true; (false = standard)

and then use {php} and {/php} to replace the tags

Thanx for the ideas.....
FrEdI

Re: Inserting PhP scripts in a template

Post by FrEdI »

Hi all ! ;D

I would like to know, if we want to insert an enter in a sql database, we will use naturally php without any problems ?  ???

Tanks a lot. ;)
JohnR

Re: Inserting PhP scripts in a template

Post by JohnR »

Anduril wrote: $config['use_smarty_php_tags'] = true; (false = standard)

and then use {php} and {/php} to replace the tags
Cool, thanks for that. I was wondering and... my question is answered!
Post Reply

Return to “Developers Discussion”