Jump to content

Outputting a hanna code via the API in a template


alan
 Share

Recommended Posts

In case anyone else* (*so that would be the future me then, when I've forgotten o_O) wants to know how to do this, I worked it out, it's probably in the docs but for the life of me I could not find it (sorry doc writers).

You have a hanna code called my_hanna_snippet and you want to output it from within a template, not from the Admin i/f.

$hanna = $modules->get('TextformatterHannaCode');
echo $hanna->render("[[my_hanna_snippet]]");

Hope this helps someone/me in the future :)

  • Like 8
  • Thanks 1
Link to comment
Share on other sites

1 hour ago, alan said:

it's probably in the docs

http://modules.processwire.com/modules/process-hanna-code/

Using Hanna Code from the API

If you want to populate Hanna Code from the API, you can do so using the render() method, like this:

$hanna = $modules->get('TextformatterHannaCode'); 
$page->body = $hanna->render($page->body);

We can just provide the hanna code itself, if we want to, just as you do it in your example.

BTW, are you sure you have never seen this in the docs? :D

 

  • Like 2
Link to comment
Share on other sites

1 hour ago, szabesz said:

We can just provide the hanna code itself, if we want to, just as you do it in your example.

BTW, are you sure you have never seen this in the docs? :D

:D

@szabesz I am pretty sure ;) the docs don't say "We can just provide the hanna code itself", I saw that part of the docs and was looking for that exact type of phrase, but even though I couldn't find that, it was enough for my trial and error to work it out, so all's well that ends well :D

  • Like 2
Link to comment
Share on other sites

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
 Share

×
×
  • Create New...