A question about snippets or pages as snippets

Hello everyone, I’m quite new here but I’ve been building a simple kirby site for my archery club, sofar so good :slight_smile:
I have encountered one problem, I’m used to being able to use a block and import it into my template, for instance using the contact_details_block (snippet) and loading it into my contact template, and on the home template.

I see kirby has snippets, but I see no way I can assign, edit content in kirby panel for a snippet. The snippets content looks hardcoded.

You can create snippets that take content from a page or site settings. Then you can insert these blocks either in the template, or if you need more flexibility, create a custom tag that inserts a snippet anywhere in your textareas, or use a checkbox or select to decide if a snippet or which snippet(s) should be inserted into a page. There are many possibilities, depending on your use case.

Thanks for your feedback,

Can I create page content “contact address”, then pull the text and title into a snippet.php file ? Because that’s what I am trying to do, then I can call the snippet in the ./templates/home.php ./templates/contact.php

I know about the snippets in text areas, but not what I want to achieve

Yes, exactly, create a snippet that reads the data you need and put it in whatever template where you need it.

Make sure to call the page that contains the content for the snippet directly, or pass it along to the snippet as a variable.

I did try that :flushed:, I created a page called “Range address” but in the snippet I’m not using the right call
<?php echo $page->text()->kirbytext() ?> does not work, so how do I do that ?

As I said above, if you use the $page variable, you have to tell Kirby what $page is supposed to be when you call the snippet, otherwise $page always refers to the current page. You can prevent that, by calling the page directly in the snippet using the page helper:

<?php
$p = page('path-to-page-with-address');
echo $p->text()->kt();
?>

Calling the snippet with a variable (when using $page within the snippet like you did above):

<?php snippet('snippet-name', array('page' => page('path-to-page-with-address')) ?>

Where did you find this:

<?php
$p = page('path-to-page-with-address');
echo $p->text()->kt();
?>

because you have been so helpful. Looking at it now makes sense, but how does one learn this ?

@texnixe thank you, I just used that snippet and of course… it works fine.

Well, I’ve been using Kirby, doing support and reading and writing Kirby documentation for a while now, so if you do things on a regular basis, you will get to learning this stuff. Meanwhile, we are here to help… :slight_smile:

If you are missing something in the docs, let me know.

All the helpers are documented here: https://getkirby.com/docs/cheatsheet#helpers