Author Topic: setVar for HREF from php echo  (Read 849 times)

0 Members and 1 Guest are viewing this topic.

NickM

  • Guest
setVar for HREF from php echo
on: Sat, 26. October 2002 - 09:34:48
Is there any way to incrporate the following php link in a template?


echo("    <a href="$PHP_SELF?query=$query&page=$next_page&limit=$limit">>></a> ");


I don't want to use "echo", I'd rather use something like this:

<a href="{tmpl_var name="right arrow"}">></a>

releasedj

  • Guest
setVar for HREF from php echo
Reply #1 on: Sat, 26. October 2002 - 16:12:00
Sure, in your php you simply do:

Code: [Select]

$right_arrow = $PHP_SELF.'?query='.urlencode$query.'&page='.$next_page.'&limit='.$limit;

$tmpl-setVar'right_arrow', $right_arrow;



and in your template you can do:

Code: [Select]

a href=tmpl_var name='right_arrow' escape='none'&gt;&gt;/a



This should work although I haven't tested it, if it doesn't work, let me know!

Regards,

Kelvin

NickM

  • Guest
setVar for HREF from php echo
Reply #2 on: Mon, 28. October 2002 - 13:12:06
Kelvin,
Thanks.  :( Unfortunately all I get on the page is a blank HREF, that is:

<a HREF="" "">

Below is the section of code where the page numbers are generated.

I've placed the tmpl code below the echo statement, within the if statement.

In theory $right_arrow should contain the same HREF info as the echo statement, but it is not passing it to the template.

There are no errors shown. Any suggestions?

--------------------------------------------------------------------------
if ($page != 0)  // Don't show back link if current page is first page.
{$back_page = $page - $limit;
 echo("<a href="$PHP_SELF?query=$query&page=$back_page&limit=$limit">back</a>    
");
}

for ($i=1; $i <= $pages; $i++) // loop through each page and give link to it.
{
 $ppage = $limit*($i - 1);
 if ($ppage == $page)
  {
  echo("<font color=red size=4><b>$i</b></font>
");   // If current page, don't give link, just text.
  }

 else{
 echo("<a href="$PHP_SELF?query=$query&page=$ppage&limit=$limit">$i</a>
");
     }

}  
//-----------------TMPL CODE IS BELOW--------------------

if (!((($page+$limit) / $limit) >= $pages) && $pages != 1) // If last page don't give next link.
{
  $next_page = $page + $limit;
  echo("    <a href="$PHP_SELF?query=$query&page=$next_page&limit=$limit">NEXT</a>
");

  $right_arrow = $PHP_SELF.'?query='.urlencode($query).'&page='.$next_page.'&limit='.$limit;
  $tmpl->setVar('right_arrow', $right_arrow);
}

NickM

  • Guest
setVar for HREF from php echo
Reply #3 on: Mon, 28. October 2002 - 14:39:16
Kelvin,
I've tried the option below in the code and followed it up with the Template code (see below) but the 'nextpage' variable refuses to show.
I get ...page=

If I replace 'nextpage' with a variable from the database (e.g. 'Price') it shows that variable.
Am I assigning the variable correctly?


PHP:
------------------------------
if (!((($page+$limit) / $limit) >= $pages) && $pages != 1) // If last page don't give next link.
{
  $next_page = $page + $limit;
  echo("    <a href="$PHP_SELF?query=$query&page=$next_page&limit=$limit">NEXT</a>
");

  $tmpl->setVar('nextpage', $next_page);
  $tmpl->setVar('limit',$limit);


Template
-------------------------------

<a href="rgordon_single_paging.php?page={tmpl_var name="nextpage"}">&gt;&gt;</a>

releasedj

  • Guest
setVar for HREF from php echo
Reply #4 on: Mon, 28. October 2002 - 16:29:12
First check that PHP is indeed executing the bit of code inside the if() brackets.

Secondly, if the 'A' tag in the template is inside a <TMPL_LOOP> tag, then you will need to set the option 'GLOBAL_VARS' to 1 in your vlibIni.php file to allow {TMPL_VAR} tag's to read from the global namespace, or you could try changing your {TMPL_VAR} tag to:
Code: [Select]

tmpl_var name=global.nextpage



If this is confusing or you don't understand what or why I have suggested the above, then take a look at the online documentation. This should help you better understand how vlibTemplate works.

Regards,

Kelvin