ProcessHannaCode icon indicating copy to clipboard operation
ProcessHannaCode copied to clipboard

HannaCode only works for one text field at the time per template

Open somatonic opened this issue 10 years ago • 3 comments

I don't know what the issue here is, but after testing a lot and some other problems with template code calling the field previous to echo the field, hanna code doesn't work.

I have a body field with hanna textformatter. I have two other textareas with hanna textformatter.

I have a Hanna code [[bild]] where I can put an image inside text. This works fine when added to body. As soon as I add a hanna tag to the second textarea, it doesn't work, the tag is replaced with "nothing". After remove the one in the body, the one in the second textarea then works.

somatonic avatar Feb 26 '15 16:02 somatonic

I just hit this issue as well.

Here's how to replicate with a fresh install of ProcessWire (2.6.4) using the Beginner Site Profile:

  1. create a template file called "_test.php". make it just have the following: <?php echo $page->body; ?>
  2. install hannacode
  3. set 'body' field to use the hannacode textformatter
  4. create a hannacode called test which loops through the about page children and outputs body of these child pages using the _test.php template and wireIncludeFile. (here's the code which you can import): !HannaCode:test:eyJuYW1lIjoidGVzdCIsInR5cGUiOiIyIiwiY29kZSI6Ijw/cGhwXG4kdGVzdF9wYWdlcyA9ICRwYWdlcy0+Z2V0KFwiXC9hYm91dFwvXCIpLT5jaGlsZHJlbjtcblxuZm9yZWFjaCgkdGVzdF9wYWdlcyBhcyAkdGVzdF9wYWdlKSB7XG4gICAgZWNobyB3aXJlUmVuZGVyRmlsZShcIl90ZXN0LnBocFwiLCBhcnJheSgncGFnZScgPT4gJHRlc3RfcGFnZSkpO1xufSJ9/!HannaCode
  5. create a page called "Test" and insert the following HannaCode into the body field: [[test]]
  6. view the page... it only outputs the body of one of the child pages. if _test.php also had some surrounding html, that would also get stripped out.

jlahijani avatar Jun 17 '15 20:06 jlahijani

As an update to my previous post, I think I know what's going on and I can simplify how to bug test this.

What's happening is when echoing a field inside a Hannacode (a field that is a textarea with ckeditor and hannacode enabled), then the output breaks.

How to replicate:

  • Create a hannacode called 'test'. type should be php. make the code for this hannacode as follows:
echo $pages->get("/")->title;
echo $pages->get("/")->body;
echo $pages->get("/about/")->title;
echo $pages->get("/about/")->body;
?>
  • insert the hannacode on a new page (call it 'test' or whatever)
[[test]]
  • view the page. it only outputs the About page body... not the 3 fields above it.
  • now use the following code for the test hannacode we just created:
echo $pages->get("/")->title;
echo $pages->get("/")->getUnformatted("body");
echo $pages->get("/about/")->title;
echo $pages->get("/about/")->getUnformatted("body");
?>
  • View the page again. The output is correct. Note how I'm using getUnformatted for the body fields. That's what circumvents the bug.

jlahijani avatar Jul 01 '15 17:07 jlahijani

I just pushed an update that I think will fix this one. Thanks.

ryancramerdesign avatar Aug 18 '16 14:08 ryancramerdesign