For the dramatic effect of a jump from the intro of a blog post to…
.
.
.
exactly the word inside the text of the blogpost, I created a custom block that basically just renders an empty span with an ID, which value I can type into the block field and then insert that block anywhere in a blogpost.
This thing works. It renders this:
<span id="ziel"></span>
Now I struggle to make the “read more” button have that ID attached to its url.
My button ist the standard button/ link, which is used in a snippet for an intro for the blog page. Like this:
<a href="<?= $article->url() ?>" class="article-more">mehr... ></a>
I tried to attach something like $article->anker()->toBlocks()
to that button, like this:
<a href="<?= $article->url() ?>#<?= $article->anker()->toBlocks() ?>" class="article-more">mehr... ></a>
But that gives me nothing.
I tried several variations of this incl. ->uid()
although I didn’t expect it to be the right guess, which it isn’t. I cannot insert the content of the “anker”-block into the button. I also guess that I will need an if statement around that link in case I don’t insert one of my “anker”-blocks, but thinking about it (again) as I type this, I think I don’t need one.
PS:
That “anker”-block (its not a full blown block, like for adults, it is maybe more of a “blocklet” ;)) is built like this:
plugins/anker/blueprints/blocks/anker.yml
name: anker
icon: url
fields:
anker:
type: slug
help: Hier eine Bezeichnung der ID als Stichwort eingeben und Anker am Ziel einfügen.
plugins/anker/snippets/blocks/anker.php
<span id="<?= $block->anker()?>"></span>
plugins/anker/index.js
panel.plugin("leblog/anker", {
blocks: {
anker: `
<input
type="anker"
placeholder=" Ziel des Ankers…?"
:value="content.anker"
@input="update({ anker: $event.target.value })"
/>
`
}
});
plugins/anker/index.php
<?php
Kirby::plugin('leblog/anker', [
'blueprints' => [
'blocks/anker' => __DIR__ . '/blueprints/blocks/anker.yml'
],
'snippets' => [
'blocks/anker' => __DIR__ . '/snippets/blocks/anker.php'
]
]);