Wallogit.com
2017 © Pedro Peláez
A concrete5.7 attribute you can use to quickly create your own attribute types., (*1)
When you add a free form attribute, you've got two fields, one where you specify the form you'll see when you enter some data and a view form you'll see when the data is presented to the end-user., (*2)
In order to to save and load fields you have to use specific names which will be replaced at runtime., (*3)
edit form:, (*4)
<strong>Name:</strong> <input type="text" name="[ATTRIBUTE(Name)]" value="[ATTRIBUTE_VALUE(Name)]">
view:, (*5)
<strong>Name:</strong> [ATTRIBUTE_VALUE(Name)]
edit form:, (*6)
<input type="hidden" name="[ATTRIBUTE(Lat)]" value="[ATTRIBUTE_VALUE(Lat)]" id="lat"><br> <input type="hidden" name="[ATTRIBUTE(Long)]" value="[ATTRIBUTE_VALUE(Long)]" id="long"><br>Address:
view:, (*7)
<div>
<strong>Address</strong>[ATTRIBUTE_VALUE(Address)] ([ATTRIBUTE_VALUE(Lat)] / [ATTRIBUTE_VALUE(Long)])
</div>
Assuming you've got the form in place from the first example using an attribute handle of test_attribute.
If you want to work with the attribute fields from a custom theme or another concrete5 method, you can use the
following approach., (*8)
// get the page we want to work with
$p = \Page::getByID(1);
// show attribute view
echo $p->getAttribute('test_attribute');
// get value of our attribute field called "Name"
$values = $p->getAttribute('test_attribute', 'variables');
echo $values['Name'];
If you want to write the values of this attribute you can simply call the setAttribute method with an array as its parameter., (*9)
// get the page we want to work with
$p = \Page::getByID(1);
// show attribute view
$p->setAttribute('test_attribute', ['Name' => 'Remo']);