0

Example:

<script type="text/javascript">
    insertVideos({
        'block':'youtubeDiv',
        'q':'keyword',
        'type':'search',
        'results':8,
        'order':'most_relevance',
        'player':'embed',
        'layout':'thumbnails'
    });
</script>

i need that 'results' as a variable to pass, at the end of process i need something like: {if $results != 0} how can i do it?

3
  • pass php info to js : <script type=..> var foobar = '<?php echo $result;?>'; </script> Commented Jul 13, 2011 at 0:49
  • 3
    JavaScript is executed on the client side. So the execution order is PHP -> Smarty -> JavaScript. Unless you want to load new content with Ajax and insert into the page, it is not possible. Commented Jul 13, 2011 at 0:53
  • exactly i need to know if that function retrieves at least 1 result after the search... actually results means max_results. How to verify that function? isset...empty... something like this? Please help Commented Jul 13, 2011 at 1:58

1 Answer 1

1

There isn't a way to access the PHP/Smarty in your javascript as they are executed in two different worlds.

The page is requested from the server. The server executes the PHP and generates the content with Smarty. The server sends the resulting HTML and javascript source code to the client. The server is now done. If another request is received, it starts over anew without knowledge of the previous request.

The client receives HTML and javascript source and displays. The insertVideos method eventually gets calls. At this point, it has no interaction with the server and the PHP/Smarty features.

From there, the javascript could make an ajax request back to the server or if I make an assumption that you only want to display the videos if the search finds some (results > 0), you can make that check in javascript and add/modify the dom elements as needed.

Sign up to request clarification or add additional context in comments.

1 Comment

ok thanks, it already doesn't show results if it doesn't find... the problem was to show or not to show a link regarding this behaviour. For now i solve including the script into another tab instead of its assigned tab.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.