HannaCode only works for one text field at the time per template
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.
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:
- create a template file called "_test.php". make it just have the following:
<?php echo $page->body; ?> - install hannacode
- set 'body' field to use the hannacode textformatter
- 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 - create a page called "Test" and insert the following HannaCode into the body field:
[[test]] - 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.
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.
I just pushed an update that I think will fix this one. Thanks.