medienbaecker / kirby-link-field

29 stars 2 forks source link

Kirby Builder Plugin #2

Closed aristotheme closed 5 years ago

aristotheme commented 5 years ago

Hi I cannot use your plugin in Kirby Builder Kirby Builder It says: type is not defined How can I solve this issue? Could you please help me?

Regards

medienbaecker commented 5 years ago

I tried to reproduce your issue and downloaded the builder field with a fresh Kirby 3 Starterkit. Seems to work:

builder

What version of Kirby and the builder field do you use? Could you please share the blueprint? Thank you!

aristotheme commented 5 years ago

Yes It works like that but If I try to put it inside accordion ( after text field )

medienbaecker commented 5 years ago

You mean in the same fieldset? Still works for me:

builder-works

aristotheme commented 5 years ago

Yess exactly! :)

Could you please write to me that's blueprint ?

medienbaecker commented 5 years ago

This is the blueprint for the page you see in the GIF:

title: Default
preset: page
fields:
  builder:
    type: builder
    fieldsets:
      aristotest:
        label: Text
        fields:
          text:
            label: Text
            type: textarea
          link:
            label: Link
            type: link
aristotheme commented 5 years ago

Thank you so much Thomas! Now it works well :)

I realised It my fault :)

On 22 Jan 2019, at 12:09, Thomas Günther notifications@github.com wrote:

title: Default preset: page fields: builder: type: builder fieldsets: aristotest: label: Text fields: text: label: Text type: textarea link: label: Link type: link

aristotheme commented 5 years ago

One More thing Thomas :)

How can I render it in php? like that <?= $data->buttonLink() ?> I got error :)

medienbaecker commented 5 years ago

It's a yaml encoded value. You can see that in the content file:

----

Button: 

link: mail@medienbaecker.com
type: email

----

…or another example:

----

Button: 

link: about-us
type: page

----

That's because I figured you will probably want to do something completely different with an email link compared to a page link or simple URL.

In your template you could do something like this:

<?php
  $buttonType = $page->button()->yaml()["type"];
  $buttonLink = $page->button()->yaml()["link"];
?>

<?php if($buttonType == "email"): ?>

  <a href="mailto:<?= $buttonLink ?>">Write an email</a>

<?php elseif($buttonType == "page"): ?>

  <?php if($buttonPage = page($buttonLink)): ?>
    <a href="<?= $buttonPage->url() ?>"><?= $buttonPage->title() ?></a>
  <?php endif ?>

<?php else: ?>

  <a href="<?= $buttonLink ?>"><?= $buttonLink ?></a>

<?php endif ?>

It's of course totally up to you what you do with those two values.

aristotheme commented 5 years ago

Thomas! Thank you so much for helping! :) You are great!

On 22 Jan 2019, at 18:25, Thomas Günther notifications@github.com wrote:

It's a yaml encoded value. You can see that in the content file:


Button:

link: mail@medienbaecker.com type: email


…or another example:


Button:

link: about-us type: page


That's because I figured you will probably want to do something completely different with an email link compared to a page link or simple URL.

In your template you could do something like this:

<?php $buttonType = $page->button()->yaml()["type"]; $buttonLink = $page->button()->yaml()["link"]; ?>

<?php if($buttonType == "email"): ?>

Write an email

<?php elseif($buttonType == "page"): ?>

<?php if($buttonPage = page($buttonLink)): ?> <?= $buttonPage->title() ?> <?php endif ?>

<?php else: ?>

<?= $buttonLink ?>

<?php endif ?> It's of course totally up to you what you do with those two values.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/medienbaecker/kirby-link-field/issues/2#issuecomment-456463752, or mute the thread https://github.com/notifications/unsubscribe-auth/AIBB2x3uqyAqLQ_z8e1YRv27c_uvnYbBks5vFzuTgaJpZM4aI4pC.