Jump to content

Hanna code inside a function [solved]


Joss
 Share

Recommended Posts

I am sure I knew how to do this once, or I was dreaming, which is equally as likely.

How can I output hanna code INSIDE a function?

So, I have this:

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

Which I would normally use stand-alone. But I want to shove it into something like this in my functions page:

function SomeFunction(){
	$out ="<div>";
      
     // hanna in here
      
      $out .="</div>";

echo $out;
}

Any clues how to do it without melting the site?

Thanks, dear people!

Link to comment
Share on other sites

Hi @elebx 

Yeah, I'm okay with the first line, erm, I think.  It was how to then get the actual specific code [[subscribebuttons]] and render it within the function, outputting it as part of my  $out chain, if you know what I mean.

  • Like 1
Link to comment
Share on other sites

I never used Hanna Code myself, but can't you just do

$buttons = $hanna->render("[[subscribebuttons]]");

and then

$out .= $buttons;

?

Don't know if you gotta have $hanna = $modules->get('TextformatterHannaCode'); inside or before your function definition though...

  • Like 3
Link to comment
Share on other sites

Got it!!

It just took waking my brain up and using the clue from @dragan

But, of course, this is inside a function - we have to use wire, don't we!!!

$hanna = wire("modules")->get('TextformatterHannaCode');
$buttons = $hanna->render("[[subscribebuttons]]");

 

  • Like 1
Link to comment
Share on other sites

@elabx was right :-)

Here't two ways in addition to @dragan's above:

 

Method 1: Call Hanna inside your function

function SomeFunction(){
	$out ="<div>";

	 // hanna in here
	 $hanna = wire('modules')->get('TextformatterHannaCode');// @note: wire!
	 $out  .= $hanna->render("[[hello]]");

      $out .="</div>";

	return  $out;
}

$out = SomeFunction();

echo $out;

Method 2: Pass your function an argument/parameter with Hanna rendered output

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

function SomeFunction2($string){
	$out ="<div>";

	 // hanna in here

	 $out  .= $string;

      $out .="</div>";

	return  $out;
}

$out = SomeFunction2($hannaString);
echo $out;

 

Edited by kongondo
  • Like 3
Link to comment
Share on other sites

3 minutes ago, Joss said:

But, of course, this is inside a function - we have to use wire, don't we!!!

That's what @elabx said! :-) ??

1 hour ago, elabx said:

Hi @Joss !!

What are you having trouble with? Most of the time I forget to call ProcessWire variables like this inside custom functions:


$hanna = wire('modules')->get('TextformatterHannaCode')

 

 

Just now, Joss said:

Beat you to it, @kongondo !!!

I do know this stuff (somewhere in my head), but it is so long since I have done any of it that I am struggling to dredge it out!

Good to see you (again) as always ?.

  • 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

  • Recently Browsing   0 members

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