2

Im running in to issues with returnJson not returning html or just returning and empty object:

$userHtml = craft()->logic->renderSiteMacro('_macros/elements', 'listing', $args);

$this->returnJson(array(
     'success' => true,
     'existing' => $userHtml
));

The return JSON is always:

{"success":true,"existing":{}}

I have double checked the html output exists and the issue persists:

  • Whether returning a simple string or large chunk of html
  • And with and without single quotes
  • When renderSiteMacro functions runs the code through the raw filter and not
4

It appears whitespace was the cause here, just running a quick whitespace filer on the return value resolved the issue:

$userHtml = craft()->logic->renderSiteMacro('_macros/elements', 'listing', $args);

$userHtml = preg_replace('~>\\s+<~m', '><', $userHtml);

$this->returnJson(array(
    'success' => true,
    'existing' => $userHtml
));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.