doucanrui1735 2017-09-27 17:16
浏览 31
已采纳

我可以在包含部分时传递php变量吗?

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.

  • 写回答

2条回答 默认 最新

  • dqwp81696 2017-09-27 17:25
    关注

    Have you tried this method as documented here? https://octobercms.com/docs/cms/partials#partial-variables

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

    EDIT

    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 %}
    

    EDIT

    Have you read the section on AJAX? https://octobercms.com/docs/ajax/introduction

    More specifically - https://octobercms.com/docs/ajax/update-partials#pushing-updates AND https://octobercms.com/docs/ajax/update-partials#update-definition

    EDIT

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

    Take a look at the JS API - https://octobercms.com/docs/ajax/javascript-api#javascript-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
    })
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 绿盟安全扫描--检测到目标站点存在javascript框架库漏洞
  • ¥30 Android STD快速启动
  • ¥15 如何使用simulink建立一个永磁同步直线电机模型?
  • ¥30 天体光谱图的的绘制并得到星表
  • ¥15 PointNet++的onnx模型只能使用一次
  • ¥20 西南科技大学数字信号处理
  • ¥15 有两个非常“自以为是”烦人的问题急期待大家解决!
  • ¥30 STM32 INMP441无法读取数据
  • ¥15 R语言绘制密度图,一个密度曲线内fill不同颜色如何实现
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包