Fog Creek Software
Discussion Board




Knowledge Base
Documentation
Terry's Tips
Darren's Tips

insert a php code

how can i insert php code (ex: $variable=Myvalue; )? I have tried in html mode <?php $variable=Myvalue; ?> but CD parse it.
Tnx

enigmista
Friday, November 28, 2003

John Conner does it and offers a few downloads that contain PHP.

He wroter a little about it here:

http://www.johnsadventures.com/backend/CityDeskImplementation/TheCityDeskImplementation.html

Look as the last paragraph of John's Item 2

tk
Friday, November 28, 2003

noting about php implementation :°

enigmista
Friday, November 28, 2003

The official XHTML method is to put it in a CDATA Marked Section. However, despite claims that CD2 is XHTML-compliant, in this regard it isn't. It has a bug (which I have reported to Fogcreek) that means it sometimes munges a marked section.

Despite this bug, it's still the best way if you actually want code in the article, like so :

<script language="php">
//<![CDATA[>
// your PHP code goes here
//<]]>
</script>

Just watch out for CD inserting spurious tags in your PHP (which you may have to remove) if you switch from HTML to normal and back. The added > ... < inside the CDATA section seem to keep it a bit happier, but I wish Fogcreek would fix the bug.

The more common alternative :

<?php
//<![CDATA[
// your PHP code goes here
//]]>
?>

although correct, is usually disasterous. CD gets very confused and may delete your code completely.

Other approaches :
-put it in a text file then pull it in on the server using SSI or PHP require
- put it in a CD variable

Michael Wild
Friday, November 28, 2003

<?php
//<![CDATA[
// your PHP code goes here
//]]>
?>

does not works

enigmista
Friday, November 28, 2003

From the help file:

On the rare occasion that you need to include these four special tags in your final site without having them be parsed by the CityScript scripting engine, the trick is to insert an extra {$$} in the middle.

Instead of: Type:
{$ {{$$}$ 
$} ${$$}} 
[[ [{$$}[ 
]] ]{$$}] 

joel goldstick
Friday, November 28, 2003

Even if you do that, CD still tries to parse the marked section, gets it wrong, and usualy leaves a few of its internal whitespace markers behind.

Plus, if you're required to mangle valid XHTML such as ]]>, CD can't be compliant.

Michael Wild
Saturday, November 29, 2003

Quote ...
<?php
//<![CDATA[
// your PHP code goes here
//]]>
?>

does not work ...

Do you mean that CD mangles it horribly when you switch views (which I know, that's why <script> is better), or that the server doesn't buy it as PHP?

Worth stating the obvious perhaps - you do need to insert all this stuff in HTML view.

Michael Wild
Saturday, November 29, 2003

*  Recent Topics

*  Fog Creek Home