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

Smarty plugin without fetch for XAJAX

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


Joined: 02 Jan 2006
Posts: 9

PostPosted: Fri Feb 29, 2008 8:51 am    Post subject: Smarty plugin without fetch for XAJAX Reply with quote

For an autosuggest feature, I've build a Smarty plugin like
Code:
{autosuggest view="table" fields="title,content" ...}


For getting the xajax script I need first to fetch() the template, after that I can display() the content with the {$xajax} into the HTML header.

Quote:
Thanks to: http://blogs.linux.ie/aj/2006/01/12/xajax-smarty-part-two/


This lead to two problems...

1. When I'm also using the Smarty plugin {array} -> http://smarty.incutio.com/?page=array, the array values are append twice: first at fetch(), then at display(). How can I solve this problem without clearing all assigned values (exept {$xajax}) before display()?

2. Since I'm using XAJAX (and fetch) the pages are loading slower. Do I really need to fetch? Is there an other way to getting the {$xajax} value without fetching?

I'm a XAJAX newbie and I love it with Smarty, please help!
Back to top
View user's profile Send private message
atomp3
Smarty Regular


Joined: 04 May 2007
Posts: 60

PostPosted: Fri Feb 29, 2008 1:28 pm    Post subject: Reply with quote

I have similiar problem I have to fetch site and than display it take a lot of time.

Solved it partialy to split template into smaller files and than fetch partialy


Last edited by atomp3 on Wed May 05, 2010 10:34 pm; edited 1 time in total
Back to top
View user's profile Send private message
RealX
Smarty Rookie


Joined: 02 Jan 2006
Posts: 9

PostPosted: Fri Feb 29, 2008 2:14 pm    Post subject: Reply with quote

Splitting the template up is what I already do... Smile

I'm thinking at two things, what should I do?

Using a session like this:

Code:
<?php
session_start();
$_SESSION['xajax'] = $xajax->getJavascript('libs/xajax/');
?>
<html>
<head>{$smarty.session.xajax}</head>
...
</html>


OR

Write the getJavascript() output to a file called output.js:
Code:
<html><head><script type="text/javascript" charset="UTF-8" src="libs/xajax/output.js"></head></html>
Back to top
View user's profile Send private message
atomp3
Smarty Regular


Joined: 04 May 2007
Posts: 60

PostPosted: Sun Mar 02, 2008 9:56 am    Post subject: Reply with quote

In index.php i have:

Code:


   $xajax-&gt;processRequest();
   $smarty-&gt;assign('xajax_javascript', $xajax-&gt;getJavascript());


so its inclued only once

Than in smarty index.tpl
Code:

{*XAJAX HANDLE*}
{$xajax_javascript}


Rest of the code are function whitch are being loaded to my needs[/code]


Last edited by atomp3 on Wed May 05, 2010 10:34 pm; edited 1 time in total
Back to top
View user's profile Send private message
RealX
Smarty Rookie


Joined: 02 Jan 2006
Posts: 9

PostPosted: Mon Mar 03, 2008 9:44 am    Post subject: Reply with quote

Ok, I keep using fetch() Sad

I just keeping the problem with the static array values before fetch. To unset the array is impossible. Is there another way for appending values inside the template?? I'm looking for days now, I really need it... Sad
Back to top
View user's profile Send private message
jimmy230
Smarty Rookie


Joined: 14 Mar 2009
Posts: 9

PostPosted: Sat Mar 14, 2009 3:23 am    Post subject: I have a working autosuggest for smarty Reply with quote

I have been working with smarty for long time but i am no really good ok.. so anyway i spent las week searching for a good script to add to my website so i decided for this one "Nodstrum i really like but one thing I needed MySqli which i dont have intalled, so I went to the code to tray to find an answer and make a smarty to get workin. so this is what i wanted, fist in my autosuggest wanted to view name and a small image.
so i really dont know how i did it but its working.

this is my index.php
**************************************************
require('config.php');

$_action = isset($_REQUEST["action"]) ? $_REQUEST["action"] : 'busca';
switch($_action)
{

case 'busca':
$queryString=$_POST["queryString"];
$RecVideo->search_now($queryString);
break;
***************************************************
now this is my function:
***************************************************
function search_now($queryString)
{

if($queryString){

$resultv = "SELECT * FROM videocat WHERE nombre LIKE \"%$queryString%\" ORDER BY id DESC LIMIT 10" ;
$resultv=mysql_query($resultv) or die (mysql_error());
$result=mysql_num_rows($resutv);


$i=0;
while ($row2 = mysql_fetch_array($resultv))
{
$res_id[$i] = $row2['id'];
$res_nombre[$i] = $row2['nombre'];
$res_imagen[$i] = $row2['imagen'];
$i++;
}

$this->tpl->assign('res_nombre', $res_nombre);
$this->tpl->assign('res_imagen', $res_imagen);
$this->tpl->assign('res_id', $res_id);
$this->tpl->display('resultadosb.tpl');

}
else
{
$this->tpl->display('error.tpl');
}

}

***********************************************
now this is my TPL resultadosb.tpl
***********************************************

<table border="0" width="300" id="table1" cellspacing="0" cellpadding="0">
<tr>
<td>{section name="i" loop="$res_id"}<ul><li>
<table border="0" width="100%" id="table2">
<tr>
<td width="20">
{thumb file="imagenes/$res_imagen[i]" width="20" height="20" link="false";}</td>
<td><a href="index.php?action=verartista&id={$res_id[i]}">
{$res_nombre[i]}</a></td>
</tr>
</table></li></ul>
{/section}</td>
</tr>
</table>
************************************************************
now this is my main file form I called buscame.tpl
************************************************************


<head>
<link rel="stylesheet" href="templates/css/style2.css" type="text/css" media="screen" />
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<script type="text/javascript" src="templates/css/jquery-1.2.1.pack.js"></script>
{literal}
<script type="text/javascript">

function lookup(inputString) {
if(inputString.length == 0) {
// Hide the suggestion box.
$('#suggestions').hide();
} else {
$.post("buscara.php", {queryString: ""+inputString+""}, function(data){
if(data.length >0) {
$('#suggestions').show();
$('#autoSuggestionsList').html(data);
}
});
}
} // lookup

function fill(thisValue) {
$('#inputString').val(thisValue);
setTimeout("$('#suggestions').hide();", 200);
}
</script>
{/literal}

</head>

<body>


<div>
<form action="index.php?action=procesar_busqueda" method="post">
<div>
Buscar Artista/Banda:
<br /><input type="submit" value="Buscar!" style="height:20px;">
<input type="text" name="buscar" size="30" AUTOCOMPLETE=OFF value="" id="inputString" onkeyup="lookup(this.value);" onblur="fill();" />
</div>

<div class="suggestionsBox" id="suggestions" style="display: none;">
<img src="templates/imagenes/upArrow.png" style="position: relative; top: -12px; left: 30px;" alt="upArrow" />
<div class="suggestionList" id="autoSuggestionsList">
&nbsp;
</div>
</div>
</form>
</div>

</body>
</html>
**********************************************************
I just include this file in evry page i wanted and is working beautiful
i can belive..
ops i almos forgot this is my style2.css file i changed i few things.
*******************************************************
.suggestionsBox {
position: absolute;
background-color: #212427;
left: 450;
margin: 5px 0px 0px 0px;
width: 300px;

-moz-border-radius: 7px;
-webkit-border-radius: 7px;
border: 2px solid #000;
color: #fff;
}

.suggestionList {
margin: 0px;
padding: 0px;
}

.suggestionList li {

margin: 0px 0px 0px 0px;
padding: 0px;
cursor: pointer;
}

.suggestionList li:hover {
background-color: #659CD8;
}

ul{
list-style-type: none;
padding: 0;
margin: 0;
}

.tooltip {
position:relative;
}
.tooltip span {
position:absolute;
left:-999em;
}
.tooltip:hover span, .tooltip:focus span {
position: absolute;
background-color: #212427;
left: 90;
margin: 5px 0px 0px 0px;
width: 400px;
-moz-border-radius: 7px;
-webkit-border-radius: 7px;
border: 2px solid #000;
color: #fff;


}

****************************************************
I hope evryone understand it. ok cheers, emailme for the wole script and help[/img]
Back to top
View user's profile Send private message
RealX
Smarty Rookie


Joined: 02 Jan 2006
Posts: 9

PostPosted: Sat Mar 14, 2009 1:34 pm    Post subject: Reply with quote

Hi Jimmy230,

Thanks for sharing. The problem I had, was about a year ago. I solved this bij using jQuery. When I need files in the HTML head, I just loop the unique results from the plugins (like autosuggest, form, multiupload, etc.) I made myself. I run also some jQuery code in markup, which I saw at the photo cycle plugin. These solutions makes my life much easier Very Happy
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
Page 1 of 1

 
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