I need to put some php into one of my .ss files (its a template) how to I tell ss to process it as .php and not .html?
We've moved the forum!
Please use forum.silverstripe.org for any new questions
(announcement).
The forum archive will stick around, but will be read only.
You can also use our Slack channel
or StackOverflow to ask for help.
Check out our community overview for more options to contribute.
Someone in #silverstripe helped me figure it out.
Hi Jerome187,
Great you learned how to do this. Would you mind sharing the titbit to help other helpless fools like myself? :)
TIA
to follow up on the request: the underlying principles that silverstripe builds upon generally discourage putting too much logic into templates, thats why we have a intentionally restricted template language that doesn't parse PHP.
PHP-code belongs into the controller or model, which can both be accessed in the template by calling methods on them.
more information:
http://doc.silverstripe.com/doku.php?id=tutorials
http://doc.silverstripe.com/doku.php?id=datamodel
http://doc.silverstripe.com/doku.php?id=templates
http://doc.silverstripe.com/doku.php?id=objectmodel
pretty much you write a php function in the page controller then call it from your template. Unfortunately this only solved one problem for me, getting the captcha image to display (and validate too) but I ran into another problem when making a form that precesses credit cards via cybersource. Creating the form in php was a huge pain, and I could not even get it working, I could not find out how to change the action to something simple, like action="https:somewhere.com/process.php" I could make the form call a php function when it gets submitted but I did not know how to make php send a form to an address. Also in the form this code was necessary:
<?php
require_once ("HOP.php");
InsertSignature("$ammount", "usd")
?>
I had no idea where to put that... I ended up making the order page outside of ss and using a page to redirect to it. Kinda lame cause its a static page and has to be edited everytime the site is changed from the cms. Does anyone know what I'm talking about and can anyone propose a better solution for this? I like SS, becides not allowing php in the templates... and making the forms, its nice for error checking but.... maybe if I knew how to use them better?
--Jerome