stacey icon indicating copy to clipboard operation
stacey copied to clipboard

Is there a way to parse PHP in template files (3.0.0)?

Open coxmi opened this issue 13 years ago • 8 comments

Or is that completely incompatible with twig / stacey 3?

It was very useful to be able to include php in partials in stacey 2.

coxmi avatar Jun 14 '12 16:06 coxmi

There isn't a way to parse PHP in template files in v3. What sort of use cases did you have in mind?

kolber avatar Apr 10 '13 01:04 kolber

I would like this as well. It gives you more freedom. For instance do I like to use PHP variables to set descriptions, keywords, etc. metadata that you can use on ie. facebook, twitter, etc. opengraph.

You only needs to have it written once, and php does the rest.

NoLooseEnds avatar May 22 '13 22:05 NoLooseEnds

Stacey uses TWIG for templates, which is quite powerful and supports variables: http://twig.sensiolabs.org/doc/templates.html#variables

You cannot use PHP in TWIG, but it has shortcuts for most methods you would ever need. The benefit is to keep template logic separate and readable.

mjau-mjau avatar Sep 02 '13 06:09 mjau-mjau

How then do I implement a contact form in Stacey?

I have looked through the twig documentation and haven't found anything that offers the mail function of PHP or a way to access the submitted values of a form. Is there a way to emulate this?

JanaDeppe avatar Oct 08 '13 19:10 JanaDeppe

I assume that would be a separate custom PHP file, possibly located in your plugins folder, which you refer to from the POST button in your form. Technically, this is neither a feature of Stacey nor TWIG, but you can still use your own PHP scripts. I would however like to see some example or recommendation in Stacey on how to organize plugins or external PHP if and when @kolber gets around to it.

I have on my agenda to add a form script to a Stacey-website shortly, and will post here when I get around to it.

mjau-mjau avatar Oct 09 '13 06:10 mjau-mjau

You are right, thanks for pointing out this possibility . Although I don't like this implementation very much.

For a simple contact form it would be much easier to redirect to the same site and give feedback dynamically on that site, especially because you cannot use the stacey templating engine in this other script, so that accessing your other partials would be a pain. For now I'm just going with "mailto:...".

JanaDeppe avatar Oct 09 '13 12:10 JanaDeppe

It is the SAME site, you would just have something like /yourphp/mail.php, and then on the form submission you would point to that file. Those form scripts can be found easily on the internet. I do agree that Stacey should have some plugins and some guidelines on how and where to add custom scripts, but per definition it not something that Stacey does for you ...

mjau-mjau avatar Oct 09 '13 16:10 mjau-mjau

@Kampfzwerg

I have a working form with phpmailer, error checking & redirect, but will need to clean it up a bit before I post it here, if you can wait a couple days.

dink avatar Oct 10 '13 07:10 dink