Hi!
I try to insert a variable from a query script into a smarttag.
$('#list').html("{list_downloads folder=medlemsdok/"+url_param+"}");
It is not rendered correct, my page shows only the whole smartytag, not the values behind:
{list_downloads folder=medlemsdok/MYVARIABLE}
Any suggestion?
I know the smart tag is correct:
If I write {list_downloads folder=medlemsdok/MYVARIABLE} directly into my div, the file list is shown as expected.
Insert variable from jquery into smarttag.
Re: Insert variable from jquery into smarttag.
You have your JavaScript code wrapped in {literal} code {/literal} means to use smarty tag inside do following:
Code: Select all
{literal}
... some js code ...
$('#list').html("{/literal}{list_downloads folder="medlemsdok/`$your_var`"}{literal}");
...the rest of the code ...
{/literal}
Re: Insert variable from jquery into smarttag.
Thanks for answer, but the variable inside the smart tag with variable still not work. Here is my complete template for writing a URL parameter into the smart tag for listing files:
Code: Select all
{process_pagedata}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<__html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
<head>
<title>{sitename} - {title}</title>
{metadata}
{stylesheet}
<__script__ src="http://code.jquery.com/jquery-1.6.4.min.js"></__script>{literal}
<__script__ type="text/javascript" language="javascript">
//GET THE URL PARAMETER ?epost=
// Parse URL Queries
function url_query( query ) {
query = query.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var expr = "[\\?&]"+query+"=([^&#]*)";
var regex = new RegExp( expr );
var results = regex.exec( window.location.href );
if( results !== null ) {
return results[1];
return decodeURIComponent(results[1].replace(/\+/g, " "));
} else {
return false;
}
}
var url_param = url_query('epost');
if( url_param ) {
epostvar = url_param; //this is the value i want to put into my smart
tag
}
{/literal}
</__script>
</head>
</__body>
<div id="list"></div>
<__script__ type="text/javascript">
{literal}
//alert(epostvar); //test the variable
$('#list').html('{/literal}{list_downloads folder="medlemsdok/'+epostvar+'"}{literal}');
{/literal}
</__script>
<__body>
</__html>
Re: Insert variable from jquery into smarttag.
This is not going to work on principle.
- Smarty tags are evaluated by the server *before* the page is sent to the client's browser.
- Javascript (as you have it) will be evaluated by the page in the client browser *after* it is received from the server.
- Smarty tags are evaluated by the server *before* the page is sent to the client's browser.
- Javascript (as you have it) will be evaluated by the page in the client browser *after* it is received from the server.
Re: Insert variable from jquery into smarttag.
Like spcherub said, i thought you were trying to inlcude a smarty var.
Re: Insert variable from jquery into smarttag.
I see..
Any idea how i can show files in a direcory based on parameters in URL?
?param=test1 -> show files in directory test1
?param=test2 -> show files in directory test2
Any idea how i can show files in a direcory based on parameters in URL?
?param=test1 -> show files in directory test1
?param=test2 -> show files in directory test2
Re: Insert variable from jquery into smarttag.
Well by using that tag that you intended to use anyway and smarty $smarty.get var:
Code: Select all
{if !empty($smarty.get.param)}
{list_downloads folder="medlemsdok/`$smarty.get.param`"}
{/if}
Re: Insert variable from jquery into smarttag.
Thanks a lot!! Works great! You made my day!! 
