将来自多个模板的javascripts与Assetic相结合

时间:2016-12-02 10:33:25

标签: javascript symfony assetic

假设我有以下树枝模板:

base.html.twig:

{% extends 'base.html.twig' %}

{% block javascripts %}
    {{ parent() }}
    {% javascripts
        '../app/Resources/js/page1_specific.js'
        '../app/Resources/js/page1_other.js'
        filter='uglifyjs2' output='page1.js'
    %}
        <script src="{{ asset_url }}" type="text/javascript"></script>
    {% endjavascripts %}
{% endblock javascripts %}

page1.html.twig:

page1

使用此代码,main.js模板会发出两个javascript请求,一个用于page1.js,另一个用于page1

是否可以用不同的方式编写它,所以我只生成一个特定于每个最终模板的大js文件,包括基页js和List<TempInOut> listTempInOut = new List<TO_TempInOut>(); List<ShiftSchedule> tempShiftSch = new List<TO_TempInOut>(); var data = (from B in tempShiftSch from C in listTempInOut where B.CompanyId == companyId && C.CompanyId == companyId && B.EmployeeId == C.EmployeeId && C.InDate >= StrOutStart && C.InDate <= StrOutEnd && B.ShiftId == item.ShiftCode && B.ShiftDate == tempInputDate select new { C.EmployeeId, C.InDate, C.Time_Date1 }).ToList(); 特定的js?

1 个答案:

答案 0 :(得分:1)

您可以在config.yml中声明基本js,如下所示:

protected static function boot()
{
    parent::boot();
    static::creating(function($model)
    {
        $model->api_token = $model->generateCode();
    });
}

protected function generateCode()
{
    return bin2hex(openssl_random_pseudo_bytes(16));
    //you can use your own random fucntion here or you can use inbuilt Crypt funciton
}

在你的javascript块中调用它:

data-open="modalName"

您可以找到更多info here