Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Javascript calling smarty
Goto page Previous  1, 2, 3, 4  Next
 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Mon Oct 14, 2013 1:45 pm    Post subject: Reply with quote

I am guessing that this:

Code:
<div id="vplayer" class="vplayer"></div> // this is the player that
      {include file="player.tpl" page="detail"} // this is the player
</div>


Has the player code hidden and when you click you want to unhide it?

Note that you can't "load" a .tpl file from javascript, you would have to make a return trip to the server (via ajax) and retrieve the rendered output from a php file calling $smarty->display('player.tpl');
Back to top
View user's profile Send private message Visit poster's website
zdig1
Smarty Rookie


Joined: 23 Sep 2013
Posts: 30

PostPosted: Mon Oct 14, 2013 7:26 pm    Post subject: Reply with quote

thx man for the time you give to answer me

this is the full version ( without template error , but wiht many ads that make browser very slow :p )

http://zdig1.biz/video/naruto-shippuuden-333-video_54dce05ae.html


beacause memmebre of site that why i still put the original player
but normaly
i have to remove the the player.tpl on detail.tpl

and will have
Code:
      <div align="center">
      <div id="vposter" class="vposter"></div>
      <div id="vplayer" class="vplayer"></div>
      </div>


when you click
vplayer will be replaced by {include file="player.tpl" page="detail"}
this by the switch on vposter and vplayer (vplayer.innerHTML )

var vposter = document.getElementById('vposter');
var vplayer = document.getElementById('vplayer');

as i said it work ok simple html but i still don't get the right variable to be called by script

you see clearly on html ( chrome line 133 ) that the variable player3 has = to the palyer.tpl and the code is correct

but when i replace on http://zdig1.biz/index/video/ttv-yt.js
Code:
vplayer.innerHTML = player3;


the script dont work

this is the methode i tryied for a month to fix Smile

but if your idea is to passs throw a php file
i dont know how to do :p i have to see the function.php cause if on detail.tpl we can se the player.tpl so this mean that is already exist on the php file !!!
PS: i am sorry for my poor english
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Mon Oct 14, 2013 7:42 pm    Post subject: Reply with quote

This is probably part of your problem:

http://d.pr/i/fBoF

You see how the contents in quotes is not escaped properly? There is no way this will work. You might take a step in the right direction by applying your content to escape modifier: |escape:javascript
Back to top
View user's profile Send private message Visit poster's website
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Mon Oct 14, 2013 7:45 pm    Post subject: Reply with quote

This:

Code:
<script>
  var player3 = '{include file="player.tpl" page="detail"}';
</script>


Try this:

Code:
<script>
  {capture assign="player"}{include file="player.tpl" page="detail"}{/capture}
  var player3 = '{$player|escape:javascript}';
</script>
Back to top
View user's profile Send private message Visit poster's website
zdig1
Smarty Rookie


Joined: 23 Sep 2013
Posts: 30

PostPosted: Mon Oct 14, 2013 9:36 pm    Post subject: Reply with quote

wawwwwwwwwwwwwwwwwwwwwwwww

it work

we have on the html on one line
Code:
 <script>
    var player3 = '           <div id=\"Playerholder\">\n         <noscript>\n         You need to have the <a href=\"http://www.macromedia.com/go/getflashplayer\">Flash Player<\/a> installed and\n         a browser with JavaScript support.\n         <\/noscript>\n         <embed src=\"http://www.dailymotion.com/swf/k5s25Tr0r33RRm4IyDU&related=0&hideInfos=1\" type=\"application/x-shockwave-flash\" width=\"555\" height=\"445\" allowFullScreen=\"true\" wmode=\"opaque\"><\/embed>\n      <\/div>\n       \n\n\n\n';
</script>



thx thx thx
Back to top
View user's profile Send private message
zdig1
Smarty Rookie


Joined: 23 Sep 2013
Posts: 30

PostPosted: Wed Oct 16, 2013 1:43 pm    Post subject: Reply with quote

hi again mort just a little step
the code is working perfectly for embed and iframe code ( and external jwplayer)
but for all link using internal flvplayer ( jwplayer and other )

http://zdig1.biz/video/watch.php?vid=18f0da067

i have this

you can see on the top the result of code ( variable player3)
i got
Quote:
You need to have the Flash Player installed and a browser with JavaScript support.

and under it the normal result ( original player.tpl)

http://imageshack.us/photo/my-images/27/kx6l.jpg/

i think the javascript function was disable by this code ??
Code:

 var player3 = '{$player|escape:javascript}';


and here is my player.tpl
http://imageshack.us/photo/my-images/546/fjhn.jpg/
Back to top
View user's profile Send private message
zdig1
Smarty Rookie


Joined: 23 Sep 2013
Posts: 30

PostPosted: Thu Oct 17, 2013 2:07 pm    Post subject: Reply with quote

i have tryed all source and video type
finally only the youtube are not working
strange audio file can be listened they dont use flash !!
this is the code for jwplayer that dont work

Code:
   {elseif $video_data.source_id == 3}
                  {literal}
                  file: '{/literal}{$video_data.direct}{literal}',
                  {/literal}


it is a part from the hole jwplayer / flv payer script

Code:
{elseif $video_data.video_player == "jwplayer"}
 
      <div id="Playerholder">
         You need to have the <a href="http://www.macromedia.com/go/getflashplayer">Flash Player</a> installed and
         a browser with JavaScript support.
      </div>
      {literal}
         <script type="text/javascript">               
            var flashvars = {
               {/literal}
               .....
               {elseif $video_data.source_id == 3}
                  {literal}
                  file: '{/literal}{$video_data.direct}{literal}',
                  {/literal}
               {else}      
                  {literal}
                  file: '{/literal}{$smarty.const._URL2}{literal}/videos.php?vid={/literal}{$video_data.uniq_id}{literal}',
                  type: 'video',
                  {/literal}
               {/if}
               {literal}
               enablejs: 'true',
               backcolor: '{/literal}{$smarty.const._BGCOLOR}{literal}',
               frontcolor: '{/literal}{$smarty.const._TIMECOLOR}{literal}',
               screencolor: '000000',
               repeat: 'false',
               autostart: '{/literal}{$smarty.const._AUTOPLAY}{literal}',
........
            };

   
            var attributes = {
               name: '{/literal}{$video_data.uniq_id}{literal}',
               id: '{/literal}{$video_data.uniq_id}{literal}'
            };
            {/literal}{$jw_flashvars_override}{literal}
            swfobject.embedSWF('{/literal}{$smarty.const._URL2}{literal}/jwplayer.swf', 'Playerholder', '{/literal}{$smarty.const._PLAYER_W}{literal}', '{/literal}{$smarty.const._PLAYER_H}{literal}', '9.0.115', false, flashvars, params, attributes);
         </script>
       {/literal}   
   


Last edited by zdig1 on Thu Oct 17, 2013 3:08 pm; edited 1 time in total
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Thu Oct 17, 2013 2:28 pm    Post subject: Reply with quote

All I can suggest is check your output, make sure your javascript is exactly as you expect it, and there are no console errors. compare the output to working code.

anytime you are putting a smarty variable into javascript string, javascript-escape it. anytime you are putting a smarty variable into a URL, url-escape it.
Back to top
View user's profile Send private message Visit poster's website
zdig1
Smarty Rookie


Joined: 23 Sep 2013
Posts: 30

PostPosted: Thu Oct 17, 2013 3:04 pm    Post subject: Reply with quote

but this solution
Code:
<script>
  {capture assign="player"}{include file="player.tpl" page="detail"}{/capture}
  var player3 = '{$player|escape:javascript}';
</script>


http://zdig1.biz/video/documentaire-super-size-me-video_18f0da067.html

give me this strange variable

Code:
<script>
    var player3 = '    \n      <div id=\"Playerholder\">\n         You need to have the <a href=\"http://www.macromedia.com/go/getflashplayer\">Flash Player<\/a> installed and\n         a browser with JavaScript support.\n      <\/div>\n      \n         <script type=\"text/javascript\">               \n            var flashvars = {\n               \n                                 \n                  file: \'http://www.youtube.com/watch?v=VbP0Ycm7T2Q\',\n                  \n                              \n               enablejs: \'true\',\n               backcolor: \'5e5e5e\',\n               frontcolor: \'545454\',\n               screencolor: \'000000\',\n               repeat: \'false\',\n               autostart: \'false\', \n               logo: \'http://zdig1.biz/video/uploads/videos/01.jpg\',\n               linktarget: \'_blank\',\n               link: \'http://zdig1.biz\',\n               image: \'http://i.ytimg.com/vi/VbP0Ycm7T2Q/0.jpg\',\n               bufferlength: \'5\',\n               controlbar: \'bottom\',\n                            \'shownavigation\':\'true\',\n               \'skin\': \'http://zdig1.biz/video/skins/modieus.zip\',\n               \'plugins\': \'http://zdig1.biz/video/drelated.swf,timeslidertooltipplugin-2,sharing-3\',\n               \'sharing.link\': \'http://zdig1.biz/video/documentaire-super-size-me-video_18f0da067.html\',\n               \'sharing.code\': encodeURIComponent(\'<iframe width=\"545\" height=\"445\" src=\"http://zdig1.biz/video/embed/18f0da067\" frameborder=\"0\" allowfullscreen seamless><\/iframe>\'),\n               \'drelated.dxmlpath\': \'http://zdig1.biz/video/relatedclips.php?vid=18f0da067\',\n               \'drelated.dposition\': \'center\', // center, bottom, top\n               \'drelated.dskin\': \'http://zdig1.biz/video/skins/grayskin2.swf\', //link to the skin\n               \'drelated.dtarget\': \'_self\', // where to open the related videos when clicked on\n               plugins: \'ltas\',\n\'ltas.cc\': \'vmqfnalsacrslqz\'\n            };\n         \n            var params = {\n               wmode: \'transparent\',\n               allowfullscreen: \'true\',\n               allowscriptaccess: \'always\',\n               allownetworking: \'all\'\n            };\n   \n            var attributes = {\n               name: \'18f0da067\',\n               id: \'18f0da067\'\n            };\n            \n            swfobject.embedSWF(\'http://zdig1.biz/video/jwplayer.swf\', \'Playerholder\', \'555\', \'445\', \'9.0.115\', false, flashvars, params, attributes);\n         <\/script>\n          \n   \n  \n\n\n\n';
  </script>   
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Thu Oct 17, 2013 3:08 pm    Post subject: Reply with quote

I think you said that part was working? That is a completely escaped string for javascript quoted string. You could just escape single quotes if you think that would help. Or only use double-quotes in the string and not escape at all.
Back to top
View user's profile Send private message Visit poster's website
zdig1
Smarty Rookie


Joined: 23 Sep 2013
Posts: 30

PostPosted: Thu Oct 17, 2013 3:24 pm    Post subject: Reply with quote

without escaping var "player 3" is correct, but
we back to the old pb ( variable crrect but dont be called on javasript"
also on chrome we can see again
Quote:
player3 is not defined


so i think we must keep the java escape

you suggets to add this not working still have the /nn
Code:
  <script>
  {capture assign="player"}{include file="player.tpl" page="detail"}{/capture}
  var player3 = "{$player|escape:javascript|escape:quotes}";
  </script>   



PS: yes the code is working only for embed and iframe of external site
wehave palyer 3 = normal caode
but for internal player (js and var ) we get this /n /n /n !!!!
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Thu Oct 17, 2013 3:47 pm    Post subject: Reply with quote

\n should be just fine in quotes. Try cleaning up the template so there are no newlines, if that is the cause for problems?
Back to top
View user's profile Send private message Visit poster's website
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Thu Oct 17, 2013 3:50 pm    Post subject: Reply with quote

You could also do something completely different: instead of assigning a string to a javascript var, put it in a hidden div.

Code:
<div id="player3" style="visibility:hidden">
{include file="player.tpl" page="detail"}
</div>


Then when it comes time to show it, just unhide the div.
Back to top
View user's profile Send private message Visit poster's website
zdig1
Smarty Rookie


Joined: 23 Sep 2013
Posts: 30

PostPosted: Thu Oct 17, 2013 5:05 pm    Post subject: Reply with quote

i can't use the new methode
because the hole 3 script alloawing auto post on open graph is based on using the variable

so i i use the methode hidden ihave to change 3 hole script

i thought the problme was only on variable
but it seem that smamrty still have many change to support external and internal variable Sad(((

my brain will exploseeeeeeeeeeeeeeeeeeeeeeeeeeee :p
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Thu Oct 17, 2013 5:13 pm    Post subject: Reply with quote

None of these problems have to do with Smarty, it has to do with your implementation. You need to decipher how the output needs to look, then adjust your code in php/smarty.

If you don't want newlines escaped, you can just escape quotes, or even escape them manually with replace. However, I don't think your problem has to do with \n in the javascript text.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Goto page Previous  1, 2, 3, 4  Next
Page 2 of 4

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP