Jump to content

Recommended Posts

Posted

Hi,

i am using multi language system

i have ajax search system (live search)

When i enter the word into search box it find the related topics but also show the other langugae titles.

How can i made it for current language?

Here is the code that i use

Quote

// Check if ajax request
if($config->ajax) {

    $searchresults = $pages->find("has_parent!=2"); // Find all published pages and save as $results
    header("Content-type: application/json"); // Set header to JSON
    echo $searchresults->toJSON(); // Output the results as JSON via the toJSON function

} else {

result attached as image

Untitled-1.jpg

Posted
On 8/31/2019 at 3:02 PM, kkalgidim said:

$searchresults->toJSON();

What does this method do? Can you share the code or explain where it comes from?

Posted

Does this works?


if($config->ajax) {

	$language = $languages->getLanguage();
    $searchresults = $pages->find("has_parent!=2, $language");
    header("Content-type: application/json"); // Set header to JSON
    echo $searchresults->toJSON(); // Output the results as JSON via the toJSON function

} else { ...

 

Posted
2 hours ago, 3fingers said:

Does this works?



if($config->ajax) {

	$language = $languages->getLanguage();
    $searchresults = $pages->find("has_parent!=2, $language");
    header("Content-type: application/json"); // Set header to JSON
    echo $searchresults->toJSON(); // Output the results as JSON via the toJSON function

} else { ...

 

no ?

i also tried
 

Quote

 

 $currentLanguage = $user->language;

$searchresults = $pages->find("has_parent!=2, $currentlanguage");

 

but its not working. i think find function does not accept variable parameter. 

maybe if i know the value of the laguage param it can be something like that

Quote

$searchresults = $pages->find("has_parent!=2, langparam={$currentlanguage}");

 

Posted

Worth a try:

if($config->ajax) {

    $searchresults = $pages->find("has_parent!=2, title.data{$user->language}"); // See below for the forum link about *.data
    header("Content-type: application/json"); // Set header to JSON
    echo $searchresults->toJSON(); // Output the results as JSON via the toJSON function

} else { ...

More on that here 

 

Posted

Try sending the current language with the Ajax request. And set the language on the response. (On mobile). 

  • Like 1
Posted
On 9/3/2019 at 11:22 PM, Mats said:

Try sending the current language with the Ajax request. And set the language on the response. (On mobile). 

@Mats can you give an example for it.

i think that there must be a simple way to filter page array to current language but i coundnt figure it out

 

 

  • 1 month later...
Posted

Hi,

i found solution and i would like to post it here. Maybe it helps someone.

i removed 

echo $searchresults->toJSON();

i used the code below instead of toJSON function

$myPages = $pages->find('template=clinic|doctor|treatment|location|resource');
$data =$myPages->explode(['title', 'url']);
echo wireEncodeJSON($data);

now it shows the current language results

You have to set the

$.typeahead({

cache: false,

 

if you dont set cache false it still show the cached language result even you change the language.

 

  • Thanks 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...