Не могу вывести значение переменной в скрипте

verfaa

Профессор
Регистрация
29 Янв 2007
Сообщения
416
Реакции
49
Хочу вывести в шаблоне smarty большой js код во внешний js-файл, но т.к. внутри js кода содержатся переменные smarty я решил занести значения переменных smarty в переменные js, а затем уже подставить js переменные в нужные места в js-файле. Короче, имею такую проблему, вот кусок кода:
Код:
<script type="text/javascript">
    profile_operation = "{$profile.operation}";
    user_id = "{$user_id}";
    button_cancel = "Cancel";
    button_add = "Add"; 
</script>
 
 
<script type="text/javascript">
$(document).ready(function(){
 
        $('#add_friend').live("click", function(e){
            e.preventDefault();
            {literal}$('#add_friend').dialog({modal: true, title:{/literal} profile_operation,
 
            buttons: { button_add : function() { add_fr(user_id, 'add_friend'); },
           
            button_cancel: function() { $(this).dialog('close'); } } });
 
        });
.......

А проблема в том, что переменные profile_operation и user_id выводятся нормально, а button_cancel и button_add выводятся как есть, т.е. подставляется button_cancel и button_add на их место, вместо того, чтобы писать "Cancel" и "Add". Почему так, ведь profile_operation и user_id подставляются и выводятся как положено???
 
  • Заблокирован
  • #2
Я конечно извиняюсь, но разве вот это
Код:
<script type="text/javascript">
    profile_operation = "{$profile.operation}";
    user_id = "{$user_id}";
    button_cancel = "Cancel";
    button_add = "Add";
</script>

Должно быть не так

Код:
<script type="text/javascript">
 var   profile_operation = "{$profile.operation}";
 var   user_id = "{$user_id}";
 var    button_cancel = "Cancel";
 var     button_add = "Add";
</script>

Вы же определяете переменные
 
Это я уже просто для примера подставил, чтобы убедиться что в переменные точно подставляются нужные значения, в скрипте так:
Код:
<script type="text/javascript">
    profile_operation = "{$profile.operation}";
    user_id = "{$user_id}";
    button_cancel = "{$profile.butcancel}"; // Выводит Cancel
    button_add = "{$profile.butadd}"; // Выводит Add
</script>
 
Назад
Сверху