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 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
zdig1
Smarty Rookie


Joined: 23 Sep 2013
Posts: 30

PostPosted: Mon Sep 23, 2013 12:10 pm    Post subject: Javascript calling smarty Reply with quote

Hi, i'm doing some modification on script using smarty 2 ,
i have 2 question
1-javascript loading partial tpl file
2-javascript calling a variable from tpl file


1/ i have page detail.tpl that use ( header.tpl , player.tpl, footer.tpl )

normaly he was inclued on other tpl like this

Code:
    {include file="player.tpl" page="detail"}


but i want to call "player.tpl" in a javascript when i click he replace picture by player the code working expet that the player dont want to apear
Code:

 playVideo : function(id, videoPageUrl)
{
        var vplayer = document.getElementById('vplayer');
        vplayer.innerHTML = 'video/player.tpl';
..........


what did i must write in the "file.js" to let it call the player.tpl when i exute the function ?
did i must add some ligne ? or changinng the path ?


Last edited by zdig1 on Mon Sep 23, 2013 4:01 pm; edited 1 time in total
Back to top
View user's profile Send private message
zdig1
Smarty Rookie


Joined: 23 Sep 2013
Posts: 30

PostPosted: Mon Sep 23, 2013 3:59 pm    Post subject: Reply with quote

2nd question: is calling variable on tpl to be used on javascript function

when i put the function on the .tpl ( internal script) it work but on javascript external i do'nt have idea the variable shall be the same as in the tpl or in the php file

for example
Code:
    {literal} <script>

  function autoPostToFeed(url) {
  'post',
  {
   video : "{/literal}{$video_link}{literal}"
  }
   }
</script> {/literal}


the external js using this (internal scxript) is working

but when i want to add it to the same js !!!
i do'nt know how to call the variable used on the details.tpl this varible{$video_link}
Code:
  function autoPostToFeed(url) {
  'post',
  {
   video : "{$video_link}"
  }
   }


---------------------------------------------------------
same thing for another variable
on tpl
Code:
{$facebook_image_src }


it only work when put the variable in the tpl like this

Code:
 {literal} <script>   var poster = "{/literal}{$facebook_image_src}{literal}"</script> {/literal}


but how i can add it to the external one !!!

on php
Code:
$facebook_image_src = show_thumb($video['uniq_id']);
.......
$smarty->assign('facebook_image_src', $facebook_image_src);


on external js i testest many but still not working ?!!!!!!!!!!!!!
Code:
   var poster = '+{/literal}+{$facebook_image_src}+{literal}+'
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Mon Sep 23, 2013 9:03 pm    Post subject: Reply with quote

Note that external Javascript is loaded directly by your browser and is not seen and processed by Smarty. So the onla chance is that Smarty information is loaded in the template into JS variables which are then passed to the external JS.

In local JS something like this should work

Code:
{literal} playVideo : function(id, videoPageUrl)
{
        var vplayer = document.getElementById('vplayer');
        vplayer.innerHTML = '{/literal}{include file="player.tpl" page="detail"}{literal}';
....
Back to top
View user's profile Send private message
zdig1
Smarty Rookie


Joined: 23 Sep 2013
Posts: 30

PostPosted: Tue Sep 24, 2013 5:48 pm    Post subject: Reply with quote

i found the solution for my second question
but for the first one, i already tested your solution and this doesnt working

you can see it on this link http://zdig1.biz/video/naruto-shippuden/317-video_7605be4c2.html

it is a timeline autoposting script so it replace the "poster" by the "player"

when i click you command dont show the player ( se about the player.tpl)
normlay you will have 2 player the old one and abpove the player called by function

you have only this text above the 2nd player
Quote:
{/literal}{include file="player.tpl" page="detail"}{literal}
Back to top
View user's profile Send private message
zdig1
Smarty Rookie


Joined: 23 Sep 2013
Posts: 30

PostPosted: Sat Sep 28, 2013 10:35 am    Post subject: Reply with quote

more than 100 view but no one have an answer !!!!
is it really the official forum ????????????

i tryed this idea but also not working

in the tpl i placed new var before the js
Code:
 
<script>
  var player3 = '{include file="player.tpl" page="detail"}';
</script>

 {literal} <script type="text/javascript" src="http://zdig1.biz/index/video/ttv-yt.js">
</script> {/literal}


and in script external ttv-yt.js i call the var
Code:

      /*
       * Remove Poster and Start Video
       */
      playVideo : function(id, videoPageUrl) {

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

         var originVideo = true;

         var pageUrl;
         if (videoPageUrl == undefined || videoPageUrl == "") {
            pageUrl = window.location + '';
         } else {
            pageUrl = videoPageUrl;
            originVideo = false;
         }

         vplayer.innerHTML = player3;
            //vplayer.innerHTML = '<div id="player"></div>';

            vplayer.style.display = 'block';
            vposter.style.display = 'none';
         

         // TODO:
         // - pause video playback until facebook pop login is dismissed / completed
         if (originVideo) {
            ttv_fb.loginAndPost(pageUrl, poster);
         } else {
            ttv_fb.delayedPostToTimeline(pageUrl);
         }
      },
 


on the html i found that the var is working
Code:
  <link rel="stylesheet" type="text/css" href="http://zdig1.biz/index/video/ttv-yt.css" />
<script>
  var player3 = ' 
         <div id="Playerholder">
         <noscript>
         You need to have the <a href="http://www.macromedia.com/go/getflashplayer">Flash Player</a> installed and
         a browser with JavaScript support.
         </noscript>
         <object width="600" height="500">   <param name="movie" value="http://www.dailymotion.com/swf/k6uj4cMpwhvaab4EbC6&related=0"></param>   <param name="wmode" value="window"></param>   <param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="always"></param>   <embed src="http://www.dailymotion.com/swf/k6uj4cMpwhvaab4EbC6&related=0" type="application/x-shockwave-flash" width="600" height="500" allowFullScreen="true" wmode="window" allowScriptAccess="always"></embed>  </object>
      </div>
         



';
      </script>


but it is not working : nothing on display => THE EXTERNAL JS DONT RECONGIZE THE VARIABLE
ypu can see the demo
http://zdig1.biz/video/naruto-shippuden/314-video_49b7106af.html
normally you must have a second player.tpl identique as the the bootom one (change poster by palyer.tpl)


Last edited by zdig1 on Sun Sep 29, 2013 1:29 pm; edited 1 time in total
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Sun Sep 29, 2013 4:33 am    Post subject: Reply with quote

I think in in external js it must be

vplayer.innerHTML = player3;
Back to top
View user's profile Send private message
zdig1
Smarty Rookie


Joined: 23 Sep 2013
Posts: 30

PostPosted: Sun Sep 29, 2013 11:46 am    Post subject: Reply with quote

you have reason i removed the ''
but the script not working any more

i though that is because i omit declaration of var
Code:
var player3 = ''


but even with this dont work
Back to top
View user's profile Send private message
zdig1
Smarty Rookie


Joined: 23 Sep 2013
Posts: 30

PostPosted: Sun Sep 29, 2013 3:33 pm    Post subject: Reply with quote

i dotn know if this can help you

the cache file template i found this

Code:
<script type="text/javascript">

  var player3 = '<?php $_smarty_tpl_vars = $this->_tpl_vars;
$this->_smarty_include(array('smarty_include_tpl_file' => "player.tpl", 'smarty_include_vars' => array('page' => 'detail')));
$this->_tpl_vars = $_smarty_tpl_vars;
unset($_smarty_tpl_vars);
 ?>';

</script>
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Mon Sep 30, 2013 7:36 pm    Post subject: Reply with quote

Okay varibale player3 must be global (remove the 'var')

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


And use in the external JS
Code:
vplayer.innerHTML = player3;
Back to top
View user's profile Send private message
zdig1
Smarty Rookie


Joined: 23 Sep 2013
Posts: 30

PostPosted: Tue Oct 01, 2013 9:49 am    Post subject: Reply with quote

script not working
in fact we have the vposter but normaly when we click on it he disapear and in the place we have the vplayer ( or blanks when i put)
Code:
vplayer.innerHTML = '';


but like you see when we click nothing happen the vposter still there and dont be removed after click

example :[url] http://zdig1.biz/video/naruto-shippuden/317-video_7605be4c2.html[/url]

on tpl
Code:

   <script type="text/javascript">
     player3 = '{include file="player.tpl" page="detail"}';
   </script>
  {literal} <script type="text/javascript" src="http://zdig1.biz/index/video/ttv-yt.js"></script> {/literal}

..........

<div align="center">
      <div id="vposter" class="vposter"></div>   
      
      <div id="vplayer" class="vplayer"></div>
   
</div>   


on js
Code:
vplayer.innerHTML = player3;

on html
Code:

   <script type="text/javascript">
     player3 = ' 
         <div id="Playerholder">
         <noscript>
         You need to have the <a href="http://www.macromedia.com/go/getflashplayer">Flash Player</a> installed and
         a browser with JavaScript support.
         </noscript>
         <object width="600" height="500">   <param name="movie" value="http://www.dailymotion.com/swf/k17t4VNhfkRbvG4bSdT&related=0"></param>   <param name="wmode" value="window"></param>   <param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="always"></param>   <embed src="http://www.dailymotion.com/swf/k17t4VNhfkRbvG4bSdT&related=0" type="application/x-shockwave-flash" width="600" height="500" allowFullScreen="true" wmode="window" allowScriptAccess="always"></embed>  </object>
      </div>
         



';
   </script>
............
<div align="center">
         
      <div id="vposter" class="vposter"></div>   
      
      <div id="vplayer" class="vplayer"></div>
Back to top
View user's profile Send private message
zdig1
Smarty Rookie


Joined: 23 Sep 2013
Posts: 30

PostPosted: Sat Oct 12, 2013 1:25 am    Post subject: Reply with quote

is it really a forum for smarty !!
no one know the answer !!!

so this mean that even the offical team for smarty dont know how to call a part of tpl !!!!!!!!!!!!!
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Sat Oct 12, 2013 3:24 am    Post subject: Reply with quote

Your code looks like a big mess, that is probably the main reason you aren't getting responses. No one is here to fix your code for you. I'm not sure why it doesn't work, but I'm also not sure what it is supposed to do. Are there php errors in the error log? Does your javascript output look right?

Demanding free help for a free product probably isn't helping you either.

Post your template source, post the *output* of the template, and we'll see if we can figure out what is not working right. I'm certain Smarty is functioning correctly, it is the implementation that needs help.
Back to top
View user's profile Send private message Visit poster's website
zdig1
Smarty Rookie


Joined: 23 Sep 2013
Posts: 30

PostPosted: Sun Oct 13, 2013 10:51 pm    Post subject: Reply with quote

the original script is on http://zdig1.biz/video
i have a lite version on http://zdig1.com/video

you can look to this page
http://zdig1.com/video/naruto-shippuuden/333-video_54dce05ae.html

you can found the html code by using firefox or chrome

the objective is to replace poster (pic) by video (player) after click on play button
this have to do 2 thing ( remove poster and replce it by player, and in same time posting on fb that user is viewing a video)

all is working perfeclty expect the part that i want to call the player
that is on other tpl file

tpl and script i'm using :
Code:
  <link rel="stylesheet" type="text/css" href="http://zdig1.biz/index/video/ttv-yt.css" />
  {literal} <script type="text/javascript" src="http://zdig1.biz/index/video/ttv.js"></script> {/literal}
  {literal} <script type="text/javascript" src="http://zdig1.biz/index/video/ttv-fb.js"></script> {/literal}
  <script> player3 = "{include file="player.tpl" page="detail"}";</script>    
  {literal} <script type="text/javascript" src="http://zdig1.biz/index/video/ttv-yt.js"></script> {/literal}
</head>

<body onload="javascript:ttv_yt.init(); ttv_fb.init()">

<div id="fb-root"></div>
{literal}<script>(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/fr_FR/all.js#xfbml=1&appId=48439698629";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>{/literal}


  <div id="socialswitch" class="socialswitch" title='Automatically posts to your facebook feed when you watch any video.'>
       <div id="socialswitchtext" class="socialswitchtext noselect" onclick="javascript:ttv_yt.toggleSocial()"></div>

      <a id="socialmsgref" title="click to remove from timeline" href="javascript:ttv_yt.removeFromTimeline()">
     <div id="socialmsg" class="socialmsg"></div></a>
    </div>   


      
      <div align="center">
      <div id="vposter" class="vposter"></div>   // this is the poster that be replaced by player
      <div id="vplayer" class="vplayer"></div> // this is the player that

      {include file="player.tpl" page="detail"} // this is the player
      </div>
      
 


i did a fucntion that witch the meta tag og pic = variable = poster
but i dont fidn the solution for a file .tpl !!!


look to http://zdig1.biz/index/video/ttv-yt.js

Code:
/*
       * Remove Poster and Start Video
       */
      playVideo : function(id, videoPageUrl) {

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

         var originVideo = true;

         var pageUrl;
         if (videoPageUrl == undefined || videoPageUrl == "") {
            pageUrl = window.location + '';
         } else {
            pageUrl = videoPageUrl;
            originVideo = false;
         }

         vplayer.innerHTML = player;
            //vplayer.innerHTML = '<div id="player"></div>';

            vplayer.style.display = 'block';
            vposter.style.display = 'none';

         // TODO:
         // - pause video playback until facebook pop login is dismissed / completed
         if (originVideo) {
            ttv_fb.loginAndPost(pageUrl, poster);
         } else {
            ttv_fb.delayedPostToTimeline(pageUrl);
         }
      },
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Sun Oct 13, 2013 11:01 pm    Post subject: Reply with quote

I turned on the chrome JS console and fired up this page:

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

Here is what I got:

http://d.pr/i/ruFt

I would focus on fixing all those errors first.

When I click on the video, I see this:

http://d.pr/i/5twq

When I close that and click the video again, it starts playing.
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 1:35 pm    Post subject: Reply with quote

yes i know, all those error are for template
nothing with smarty or the script

i told you i moved a lite versionb to zdig1.com

the original is on zdig1.biz

and the missing png file was for test on html static page and now when i want to export the working script to the smarty tpl

the function that remove poster and replace it by player dont work

normaly when you click on play you must have a similar player like the above one
this player is the player.tpl that i want to call on this script
Back to top
View user's profile Send private message
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 1, 2, 3, 4  Next
Page 1 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