Structur fields flexibel placement

Hello,

there a way to place a structur fields content in to a textfield with a tag?

Text text text text
(my structurfield01) 
text text text

greetings perry

What sort of data do you want to have there? There is no Kirbytag for that. Another option would be to use a standard structure field but use a tag to place a snippet with the structure field data into the textarea.

the data is diferents two col tables , for the editor it is easier to fil out a structur fields than a md table tag.

You can create your own Kirbytag for this and then use it like this:

Text text text text
(structure: myfieldname) 
text text text

If the field name is always the same, you can leave out the param and hardcode it in the tag, it will then become:

Text text text text
(structure:) 
text text text

Thank you @lukasbestle.

Hello,

I create my first tag!
but I don’t unterstand how pass an argument to the tag.

(table: table01)

(table: table02)

Blueprint

  table01:
    label: Tabele 01
    type: structure
    entry: >
      
      {{spalte01}} {{spalte02}}
    fields:
      spalte01:
        label: Spalte01
        type: text
        style: table
      spalte02:
        label: Spalte02
        type: text
        style: table

  table02:
    label: Tabele 02
    type: structure
    entry: >
      
      {{spalte01}} {{spalte02}}
    fields:
      spalte01:
        label: Spalte01
        type: text
        style: table
      spalte02:
        label: Spalte02
        type: text
        style: table

Tag

<?php

kirbytext::$tags['table01'] = array(
  'html' => function($tag) {

  				$html =	'<table>';
  				
  				 foreach($tag->page()->table01()->toStructure() as $table01) {
  				 	$html .= '<tr>';
  				 	$html .= '<td>';
  				 	$html .= $table01->spalte01()->html();
  				 	$html .= '</td>';
  				 	$html .= '<td>';
  				 	$html .= $table01->spalte02()->html();
  				 	$html .= '</td>';
  				 	$html .= '</tr>';
  				 }

  				 $html .=	'</table>';


return $html;
  }
);

?>

Adding arguments to a tag is described in the tutorial I linked to above. It’s the second example. :slight_smile:

<?php

kirbytext::$tags['table'] = array(
  'html' => function($tag) {
    $html = '<table>';
    
    $field = $tag->attr('table');
    foreach($tag->page()->$field()->toStructure() as $table) {
      $html .= '<tr>';
      $html .= '<td>';
      $html .= $table->spalte01()->html();
      $html .= '</td>';
      $html .= '<td>';
      $html .= $table->spalte02()->html();
      $html .= '</td>';
      $html .= '</tr>';
    }

    $html .= '</table>';

    return $html;
  }
);
2 Likes

@lukasbestle thank you very much !