In my frontend I have this “partial content” div with a button that, once clicked, I’d like to process the field somewhere else in the page template… hence optimizing the page since the field in question has lots of images, videos, etc.
<div class="content--partial">
<?php echo $page->full_content()->excerpt(90, 'words') ?>
<a href="#">Keep reading</a>
</div>
<div class="content--full">
#### load the same field here in full, as kirbytext()
</div>
Clicking the link would process the same field as kirbytext() instead of rendering the whole thing on page load.
3.Create an ajax.php template where you retrieve the content you want to insert into the empty container (extract the right page from the url or hardcode the page if it is only one) …
<?php
echo page('abc')->text()->kt();
?>
4.Create your ajax call (the following code requires jQuery)
I wound’t know how to solve this whatsoever… specially because these more “advanced” stuff aren’t well documented… the docs page for the tpl:load for example… it looks like it’s there for people who know what TPL stands for.
For some of this stuff you kinda need to dig into the source code, or accept that you might struggle to use the kit to its full potential. But that’s what the forum is here for!
tpl::load is the class method that kirby uses to actuate your template code. The template expects data and a file. It passes the data to the file and then returns the output as default, or optionally echos it there and then (if its third variable is set to false).
Bear in mind that when you use a custom route you are overriding the default kirby processes. If you want to use normal templates then you need to return a string of a page name, a page object, or an array where the first parameter is the page, and the second the data you want to pass to that page.
Alternatively you can handle the output yourself, either by putting together a response object, or just echoing stuff directly. Ideally you would construct a response object, but that isn’t critical in this case.