Use of a variable in a snippet

#1

For a form in different languages (but not an multilang website) I use blueprints with the form label names for the different languages. In general the website has only one language.

I’ve a snippet for a input field:

<label for="<?= $field ?>" class="form-label">
 LABEL
</label>
<input class="form-input" type="text" name="<?= $field ?>" value="" required>

And in the template I want to use this for every input field:

<?php snippet('forms/input', ['field' => 'first_name']) ?>

In the blueprint for the english form:

first_name: First name
last_name: Last name

etc.

The same for the other languages.

Now I would like to get the label name LABEL in the Snippet.

When I try to use this code for LABEL (see above):

<?= $page->content()->get('first_name')->html() ?>

I get the corret label, but when I use it with the variable:

<?= $page->content()->get($field)->html() ?>

…It doesn’t work…

How is the right way to solve this?
The labels don’t have to be in the blueprint, but this way it would be possible to be edited in the panel…

0 Likes

#2

I’m sorry… It was a simple typo mistake in the variable name (firstname vs first_name)… the code is correct…

0 Likes