L
L
Light7772015-12-30 21:21:41
JavaScript
Light777, 2015-12-30 21:21:41

Why doesn't php to javascript work in Yii2?

I register javascript code in main.php
But it does not see the function <?php Yii::getAlias("@web")?>
How can I add an alias to the image path?

<?php  $this->registerJs(
        'jQuery(document).ready(function($){
    var smallWindow = false;

    $(window).scroll(function() {
        var scroll = $(window).scrollTop();

        if (scroll >= 50) {
            $("#logo-image").attr("src", "<?php Yii::getAlias("@web")?>/images/logos/Monogram.png")
            $(".important-class").addClass("padding-on-my-header");
        }
        if (scroll < 50) {
            $(".important-class").removeClass("padding-on-my-header");
            $("#logo-image").attr("src", "<?php Yii::getAlias("@web")?>/images/logos/PetCare_Monogram.png")
        }
    }).resize(function(){
        if ( !smallWindow && this.innerWidth <= 1024 ) {
            smallWindow = true;
            $(".top-bar-section").find("ul.right").hide(0).delay(500).show(0);
        }
        if ( smallWindow && this.innerWidth > 1024 ) {
            smallWindow = false;
        }
    });
});');

         ?>

Answer the question

In order to leave comments, you need to log in

4 answer(s)
V
Vitaly Artemyev, 2015-12-31
@Light777

<?php  $this->registerJs(
        'jQuery(document).ready(function($){
    var smallWindow = false;

    $(window).scroll(function() {
        var scroll = $(window).scrollTop();

        if (scroll >= 50) {
            $("#logo-image").attr("src", "'.Yii::getAlias("@web").'/images/logos/Monogram.png")
            $(".important-class").addClass("padding-on-my-header");
        }
        if (scroll < 50) {
            $(".important-class").removeClass("padding-on-my-header");
            $("#logo-image").attr("src", "'.Yii::getAlias("@web").'/images/logos/PetCare_Monogram.png")
        }
    }).resize(function(){
        if ( !smallWindow && this.innerWidth <= 1024 ) {
            smallWindow = true;
            $(".top-bar-section").find("ul.right").hide(0).delay(500).show(0);
        }
        if ( smallWindow && this.innerWidth > 1024 ) {
            smallWindow = false;
        }
    });
});');

         ?>

K
Kirill, 2015-12-30
@synnvkz

I am not a Yii expert, but I can assume that due to the fact that you have a php tag in the php tag

D
Dmitry Bay, 2015-12-30
@kawabanga

m.b. echo?

G
glamurchik, 2016-01-11
@glamurchik

keyword "concatenation"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question