[英]How can I pass variables to a partial in Handlebars (v1.3 with Assemble)?
[英]Can i pass php variables when including a partial?
我是OctoberCMS的新手,所以我不了解很多事情。 我閱讀了十月份的文檔,並且知道如何以靜態方式使用局部變量時傳遞變量:
{% partial "location" city="Vancouver" country="Canada" %}
我的問題是我需要使用php或js變量。 假設我有一個輸入字段,用戶在其中輸入ID,然后在按下按鈕后,我要將ID傳遞給局部代碼。 我正在嘗試做這樣的事情:
{% partial "location" city=$city country=$country %}
有人能幫我嗎? 謝謝。
您是否嘗試過此處記錄的此方法? https://octobercms.com/docs/cms/partials#partial-variables
{% partial "location" city=city country=country %}
編輯
順便說一句,您需要在onStart函數中定義頁面變量。
url = "/blah"
layout = "default"
==
<?
function onStart()
{
$this['country'] = ...;
$this['city'] = ...;
}
?>
==
{% partial "location" city=city country=country %}
編輯
您閱讀過有關AJAX的部分嗎?
https://octobercms.com/docs/ajax/introduction
更具體地說
-https :
//octobercms.com/docs/ajax/update-partials#pushing-updates和
https://octobercms.com/docs/ajax/update-partials#update-definition
編輯
只需重新閱讀您的原始問題,您就會在問有關綁定到表單元素而不是AJAX的問題。
看看JS API- https://octobercms.com/docs/ajax/javascript-api#javascript-api
我認為您可以執行以下操作:
<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
})
您可以通過以下方式在局部變量中使用變量:
<p>Country: {{ country }}, city: {{ city }}.</p>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.