Joss Posted November 24, 2019 Posted November 24, 2019 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!
elabx Posted November 24, 2019 Posted November 24, 2019 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') 1
Joss Posted November 24, 2019 Author Posted November 24, 2019 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. 1
elabx Posted November 24, 2019 Posted November 24, 2019 23 minutes ago, Joss said: t was how to then get the actual specific code [[subscribebuttons]] and render it within the function ohhhhh got it! no idea man hahaha 1
dragan Posted November 24, 2019 Posted November 24, 2019 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... 3
Joss Posted November 24, 2019 Author Posted November 24, 2019 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]]"); 1
kongondo Posted November 24, 2019 Posted November 24, 2019 (edited) @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 November 24, 2019 by kongondo 3
Joss Posted November 24, 2019 Author Posted November 24, 2019 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!
kongondo Posted November 24, 2019 Posted November 24, 2019 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 ?. 2
Joss Posted November 24, 2019 Author Posted November 24, 2019 2 minutes ago, kongondo said: Good to see you (again) as always ?. You too, mate! 1
elabx Posted November 25, 2019 Posted November 25, 2019 5 hours ago, elabx said: ohhhhh got it! no idea man hahaha Here I had thought you wanted the actual PHP code inside the function! lol
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now