Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Options

php inside javascript file

edited November 2007 in Vanilla 1.0 Help
How do i include php inside javascript file
I have a file called Vcal.js.php which looks like this
<?php header("Content-Type: text/javascript"); include("../../../appg/settings.php"); include("../../../appg/init_vanilla.php"); global $Context; ?> $(document).ready(function() { $("form#frmPostDiscussion").before('<div class="ErrorContainer"><div class="ErrorTitle"><?php $Context->GetDefinition('VcalErrorTitle') ?></div><div class="Error"><?php $Context->GetDefinition('VcalError') ?></div></div>'); });

the php code <?php $Context->GetDefinition('VcalErrorTitle') ?> result in nothing. It cannot find the definition

Comments

  • Options
    Why not just pass that as an argument to the js function?
  • Options
    edited November 2007
    It is <?php echo $Context->GetDefinition('VcalErrorTitle'); ?>
    or <?=$Context->GetDefinition('VcalErrorTitle')?>.

    <?php $Context->GetDefinition('VcalErrorTitle') ?> is nothing. :P
  • Options
    Perfecto Amigo IShkyBoy :)
  • Options
    Could you then load that into a variable in js?
  • Options
    yup thats the idea
    you can add php in css file as well just like above and have css values be generated by php
  • Options
    edited November 2007
    If you use php to serve some Javascript, you should set the header to allow caching:header('Expires: '. gmdate( 'D, d M Y H:i:s', time() + 3600) . ' GMT'); header('Last-Modified: ' . gmdate( 'D, d M Y H:i:s', $LastModification) . ' GMT'); header('ETag: ' . $LastModification); header('Content-Type: text/javascript'); header('Pragma: '); //overwrite the one set in appg/header.php
    $LastModification should the last modification time of the php file or one of the file that set the variable that it uses.
  • Options
    Dino me no underishtand thish
    can you explain $LastModification one more time
  • Options
    edited November 2007
    the Last-Modified tell the browser when the file has been modified the last time, so that it can request the server to send it only if its version is outdated.
    if example.js.php use a variable set into settings.php its the last modification time will its own modification time or the one of settings.php.

    You script before sending the data to the browse should check has a up to date version of the document (check $_SERVER['HTTP_IF_MODIFIED_SINCE']) and send header($_SERVER['SERVER_PROTOCOL'] .' 304 Not Modified'); exit(); if it is up to date.
This discussion has been closed.