GetSimple Support Forum
how to make return work - Printable Version

+- GetSimple Support Forum (http://get-simple.info/forums)
+-- Forum: GetSimple (http://get-simple.info/forums/forumdisplay.php?fid=3)
+--- Forum: Developer Discussions (http://get-simple.info/forums/forumdisplay.php?fid=8)
+--- Thread: how to make return work (/showthread.php?tid=16033)



how to make return work - Felix - 2021-02-06

Hi,

In some cases I do not want to echo, but need to return the content of:

get_page_content();

get_component();

======================================

The following does not work:

get_page_content(false);
return_page_content();

get_component(false);
return_component();

======================================

Does anyone know a way to make return work for this ?


RE: how to make return work - shawn_a - 2021-02-07

what version ?


RE: how to make return work - shawn_a - 2021-02-07

hmm there is none for content... odd
I know there is a way to get content , and im sure this has come up many times...

lol maybe not, I am stumped


RE: how to make return work - shawn_a - 2021-02-07

3.4 there is returnPageContent()


RE: how to make return work - shawn_a - 2021-02-07

you could use ob buffer with get_page_content in 3.x, if not i18n surely has something


RE: how to make return work - Felix - 2021-02-07

Hi,
Thanks for stepping in,
sorry I forgot to mention that I am building with the 3.3.16

What I could find is returnPageContent('slug');
This works fine for 1 language

The i18n plugin has return_i18n_component('slug') but it returns the output unprocessed
(includes the php tags, quotes and semicolon)

=======================================================

Yes the best working solution seems to make use of PHP output buffering
It works also nice with multi-language and it even allows
chaining api calls:

Working example on a template file:

PHP Code:
<?php
ob_start
();
get_page_content();
get_i18n_component('test');
$maincontent .= ob_get_clean();
?>

On the front:

Code:
<div class="">
<?php echo $maincontent ; ?>
</div>

Works flawlessly ...

===========================================================

It is said that you have to be careful with ob memory usage

So I checked with memory_get_usage()

PHP Code:
echo memory_get_usage() . "<br>";
ob_start();
get_page_content();
get_i18n_component('test');
$maincontent .= ob_get_clean();
echo 
memory_get_usage() . "<br>");
unset(
$maincontent);
echo 
memory_get_usage() . "<br>"


There is no memory usage problem at allĀ 

F.