Can I Pass Php Variables When Including A Partial?

- 1 answer

I am new to OctoberCMS so I don't know a lot of things. I read the October documentation and i know how to pass variables when using partials in the static way:

{% partial "location" city="Vancouver" country="Canada" %}

My problem is that I need to use php or js variables. Let's say I have an input field where the user writes an ID, then after a button is pressed I want to pass the ID to a partial. I am trying to do something like this :

{% partial "location" city=$city country=$country %}

Can someone help me? Thank you.



Have you tried this method as documented here?

{% partial "location" city=city country=country %}


As an aside, you need to define your page variables in the onStart function.

url = "/blah"
layout = "default"
function onStart()
    $this['country'] = ...;
    $this['city'] = ...;
{% partial "location" city=city country=country %}


Have you read the section on AJAX?

More specifically - AND


Just re-read your original question and you're asking about binding to form elements, not AJAX.

Take a look at the JS API -

I think you could do something like:

<form onsubmit="$(this).request('onMyProcessingMethod'); return false;">

$('form').request('onMyProcessingMethod', {
    update: {myPartialName: '.whereIWantTheOutputToGo'},
    data: {country: 'Canada'} // Not 100% sure how to access form input; maybe ID selector