Display Blueprint Labels on Front End

Hi all!

I’ve searched the docs but cannot seem to figure out how to output the label from a blueprint. I have this blueprint for example.

skills:
   label: Skills
   type: checkboxes
   options:
     PHP: PHP
     HTML5: HTML5
     CSS/Sass: CSS/Sass
     jQuery: jQuery/JS
     Design: Design
     Photography: Photography
     Video: Video Production
     Icon Development: Icon Development
     Kirby CMS: Kirby CMS
     Wordpress: Wordpress
     Drupal: Drupal
     getSimple: getSimple

On the Front End I have the checkboxes outputting correctly but I’d like to have the label outputted as well. So something like this, where Skills is outputted.

Skills: Wordpress, Drupal, PHP etc…

        <?php echo $page->skills()->label(); ?><!--How to output the label-->
   		<ul class="project-skills">
		  <?php foreach($page->skills()->split() as $skill): ?>
		  <li><?php echo html($skill); ?></li>
		  <?php endforeach ?>
		</ul>

Sorry for such a rudimentary question :slight_smile: still a noob. Thank you in advance!!!

I don’t think that’s possible.

Anyway, why not just type "Skills" there? In this case, it seems a bit unnecessary to fetch that title from the label or even another field.

1 Like

There is a plugin for that: Kirby Architect

But I agree with @invasoria, just to get the field label, that’s overkill and will unnecessarily slow down your page.

As the label is the same as the field name, you might as well do this:

<?= ucfirst($page->skills()->key()) ?>

For cases where the field key is different from the label, you can use a label map to get the label (you would have to build that manually, though)

c::set('labelMap', array(
'skills' => 'Skills',

));

You can the fetch it in your template like this;

<?= c::get('labelMap')[$page->skills()->key()] ?>
2 Likes

I agree with the rest that parsing the blueprint is overkill in this case.

Other possible solutions could be:

  • Custom language variables where you add your key and what that key should be translated to, like “skills” would be “Skills”.
  • Use ucfirst to use the key but make the first letter uppercase.
  • If statement in the template. If key is “skills” then write “Skills”.
  • The same as above but inside a controller.

So you need to figure out the best way for you but I think that key is the key here. :slight_smile:

1 Like

@invasoria I really wanted to just make sure the template stays clean as possible but seeing some of the other solutions from @jenstornell and @texnixe as well, I think the easiest route would be to just write it in for now. The other solutions/plugins look promising. I had no idea that there was a performance issue. Thank you all for your help!!! :slight_smile:

1 Like