Forum for discussing general topics related to Couch.
8 posts Page 1 of 1
Hi,
I have extremly problems to parse php in couch CMS on snippets or own files.
If i change the <?php to </cms:php> it works but first I don't understand why this is necessary. And Couch is really the first software which I have seen that the php tags are replaced.
And if I want to mix it up with HTML like:
Code: Select all
<link rel="stylesheet" property="stylesheet" href="<cms:php> echo url($CSSPath) </cms:php>?version=<cms:php> echo $CSSFileTime </cms:php>">


Have someone some ideas why I have this strange problems with PHP?
Hi,

Perhaps the following would help -
viewtopic.php?f=2&t=11486&p=30590#p30590
KDJFS, PHP code must be valid in all situations - whether used within 'cms:php' block or in '<?php' code. PHP parser is expecting ';' or ',' after statements, which is missing.

Try this variant –
Code: Select all
href="<cms:php>global $CSSFileTime; echo url($CSSPath), '?version=', $CSSFileTime;</cms:php>"


Replacing PHP tags with 'cms:php' is not necessary ☺ Following also works (provided your function and variable are available in global scope) –
Code: Select all
href="<?php echo url($CSSPath), '?version=', $CSSFileTime; ?>"
@trendoman,
Straight <?php ?> tags will work only on the main (masterpage) template (i.e. one with the .php extension invoked directly through the browser) - for code placed within embedded snippets (which appears to be what OP mentioned), we'll have to use the Couch <cms:php> tags as <?php ?> won't work within them.
KK wrote: @trendoman,
Straight <?php ?> tags will work only on the main (masterpage) template (i.e. one with the .php extension invoked directly through the browser) - for code placed within embedded snippets (which appears to be what OP mentioned), we'll have to use the Couch <cms:php> tags as <?php ?> won't work within them.


That's correct only for the snippets loaded by Couch i.e. 'cms:embed'. We have seen 'snippets' included with <?php include() ?> ☺ Given the criginal post it is hard to guess how snippets are treated.

I'll try to add more context to my answers, if that's what you meant.
Yes it is inside a snippet.
I want also include some libs like scssphp or whoops.
This methodic makes it really annoying to use some stuff additional of couch.
But back to the entry problem, also
Code: Select all
<link rel="stylesheet" property="stylesheet" href="<cms:php> echo urlencode($CSSPath); </cms:php>?version=<cms:php> echo $CSSFileTime; </cms:php>">

doesn't show the echo parts.
Or should I use classic include?

It's a little bit like lotto if something will work or not.
As given in the link I mentioned above (viewtopic.php?f=2&t=11486&p=30590#p30590), we need to use 'global' e.g. as follows -
Code: Select all
<link rel="stylesheet" property="stylesheet" href="<cms:php> global $CSSPath; echo urlencode($CSSPath); </cms:php>?version=<cms:php> global $CSSFileTime; echo $CSSFileTime; </cms:php>">

Please go through the points discussed there and things should get a little easier interfacing with raw PHP.
Hope this helps.
KDJFS, for the question you asked in the first post — why this is necessary — there is this line in Documentation » php, quote:
The enclosed PHP code can contain Couch tags which will be fully executed to yield the final PHP code that will be eventually evaled to return the output.

It is that we can have flexibility over when to execute PHP code. Usually PHP goes always first, but with 'cms:php' we have it running after some Couch tags. Let me know if you need more examples with code. ☺
8 posts Page 1 of 1
cron