[pmwiki-users] Insert text only once
Petko Yotov
5ko at free.fr
Tue Aug 14 20:52:11 CDT 2007
On Wednesday 15 August 2007, Richard Haven wrote:
> In one, I have some javascript that should exist only once per page in
> addition to another tag. How do I detect that the user has use (:tag
> blah:) more than once so I can omit emitting the singleton content?
>
> I am trying
>
> SDV('$Flag']), 0);
>
> global Flag;
>
> if ($Flag == 0){
>
> $codeSnippet .= "<script type=\"text/javascript\"
> src=\https://domain.com/init.js <https://domain.com/init.js>
> \"></script>";
>
> $Flag = 0;
>
> }
>
> Am I on the right track ?
If it is inside a function, then first declare global:
global $Flag; // Note the "$"
SDV($Flag, 0);// Note, you had errors above
if($Flag == 0) { do whatever }
$Flag = 1;
You can also use the same key in a $HTMLHeaderFmt array element:
//no need to test for $Flag
$HTMLHeaderFmt['init.js'] =
'<script type="text/javascript" src="/init.js"></script>';
This will immediately put the javascript in the header of the HTML page; if it
is applied more than once, it still prints it once.
See http://www.pmwiki.org/wiki/PmWiki/LayoutVariables also for $HTMLFooterFmt.
Have fun,
Petko
More information about the pmwiki-users
mailing list