VaeML and PHP working together
  • This question came in via E-Mail:

    Is there a way to pass VaeML into PHP? For example, if I want to capture the current ID () then pass it into a PHP function on the same page?

    Lastly, will PHP includes work properly within Vae pages? I've got some PHP function pages I want to call instead of having the code in each page and it doesn't seem to be working the way I expect it to.

  • 1 Answer sorted by
  • I'll answer your 2nd question first: Yes, the standard PHP include tags, such as include(), require(), include_once(), and require_once() will work just fine.

    Note however, that you cannot use PHP code directly from a VaeML template file. (Though you can use the <v? ?> syntax, or use <v=somefunction()> to render the results of a function defined elsewhere, such as __vae.php).

    As far as the first question, there are many ways to do what you want.

    1. Whenever you're in a <v? ?> block, Vae will set the variable $context to hold the current VaeQL context. So you could get the current ID by looking at $context->id.

    2. Also, if you're on a page where the entire page starts within a context (for example a permalinked page), $_REQUEST['id'] will be set to the ID of the entry.

    I hope that helps.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In Apply for Membership

In this Discussion