S
S
Sergey Beloventsev2018-05-30 14:15:05
Yii
Sergey Beloventsev, 2018-05-30 14:15:05

How to display built-in js scripts in Yii2 in a separate file?

There are built-in Yii2 scripts, for example yiiActiveForm. Which are embedded into the page by a script between the tags .
Is it possible to display it in a separate file.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Timofeev, 2018-05-30
@webinar

We'll have to generate and connect it. What will it give? A separate file is a separate request (not optimal). This code is unique to the current page and is required only on it, so there is no point in including it in main.js either. The place for such pieces of code is in the body. What are you trying to achieve in the end? Maybe a separate file is not the right way?

P
profaller, 2018-05-30
@profaller

There is always an opportunity to do anything, the question is - why do you need it? These scripts are written right into the page for a reason, because they are generated dynamically.
If you really really want to, you can, for example, make a child web / View, and override registerJs with it and check the signatures of Yii widgets (for example, GridView can be determined by the presence of "yiiGridView"). Or, if it’s completely good, then you can check the function call through debug_backtrace and see in which class registerJs is called. Then I think you will figure out how to do it yourself.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question