Kirby fields hidden in markdown

Hello all,

I want to know if it’s possible to have kirby fields, in the text contents, hidden in markdown.

I need this because I’m making git of each article folder, with the content file as README.md, and pushing them to github. I’ve found how to use .md instead of .txt with c::set('content.file.extension', 'md'); but when I preview the README.md in the git (example on github) the kirby fields are shown, and i want them hidden but working on kirby, so with only text: content shown!

Here’s the example README.md file:

Title: Project Test

----

Year: 2015

----

Tags: article

----

Text: All my markdown here.

It’s just a text file, I don’t see how it would be possible to hide some fields on GitHub. Maybe you could have .txt files for Kirby and then auto-generate an .md file for GitHub.

1 Like

Ok, i’ve found a solution, but only modifing kirby core:

In /kirby/core/content.php after

$this->raw = str_replace(BOM, '', file_get_contents($this->root));

add

// uncomment markdown
$this->raw = str_replace("<!--", "", $this->raw);
$this->raw = str_replace("-->", "", $this->raw);

and now you can have commented metadata!!

<!--

Title: Project Test

----

Year: 2014

----

Tags: article

----

Text:

-->
all markdown text here outside comment

Found a much better solution:


Title: Project Test

----

Text: README.md

We do a custom field method (inside /site/plugins/methods.php) that return the file:

// return file
field::$methods['get_file'] = function($field) {
	$file = kirby()->page()->file($field->value);
	return $file;
};

So we can use get_file() method to get the external file, and work with it:

$file = $page->text()->get_file();
$text = $file->read();
echo date("d/m/Y H:i", filemtime($file));

The problem is that $text right now is not an object, like the one you have on kirby, so you can’t use ->kibrytext(); and other methods on it, still you can use kirbytext($text);