Advanced Fields For Magento 2
Advanced Fields for Magento 2 gives Admins, Designers and Developers the ability to
create as many additional fields for text and file data (such as pictures, video and PDF
files) for use as custom content blocks on CMS pages as needed. Advanced Fields provides
4 types of fields.
1. Text
2. Text area
3. Wysiwyg Editor
4. File
1. Add Advanced Fields By Default On A Magento Page
Users can add custom inputs to a CMS page by default, for example below is a block being
added to a CMS Home Page.
!
To add a new custom field to the homepage simply:
1. Created new custom field under Advanced Fields > Bricks Advanced Fields > Add New
2. After creating the fields go to Content >Blocks > Home Page Block > Edit
3. To add custom block to the top of the page you can use the following short code:
1. {{block class="Bricks\AdvanceFields\Block\Advancefields\Field"
name="advancefields_listing" template="Bricks_AdvanceFields::advancefields/
field.phtml" field_id="1" variable=“field_value"}}
2. Where field_id is the id of field which you want to show on the home page.
4. The variable can be edited to field_value to show custom field value or you can use
field_title to show the field title.
!
For example above code will add new field with the id 1 and show field_value on the
homepage as shown below.
!
Suppose you want to add both field title and field value then you have to add below code
{{block class="Bricks\AdvanceFields\Block\Advancefields\Field"
name="advancefields_listing" template="Bricks_AdvanceFields::advancefields/field.phtml"
field_id="1" variable="field_title"}}
{{block class="Bricks\AdvanceFields\Block\Advancefields\Field"
name="advancefields_listing" template="Bricks_AdvanceFields::advancefields/field.phtml"
field_id="1" variable="field_value"}}
After adding the above code both the field title and field value will be displayed
!
In this same manner, we can add images as custom banner in the custom fields. For
example:
!
Added Home Banner Image which has id 3 so you can add below code in the home page
block
{{block class="Bricks\AdvanceFields\Block\Advancefields\Field"
name="advancefields_listing" template="Bricks_AdvanceFields::advancefields/
field.phtml" field_id="3" variable="field_title"}}
{{block class="Bricks\AdvanceFields\Block\Advancefields\Field"
name="advancefields_listing" template="Bricks_AdvanceFields::advancefields/
field.phtml" field_id="3" variable="field_value"}}
The image banner will be displayed.
!
You can also move the position of the block code as per your need on the page like we
have moved the block code in the Hot Sellers Section.
!
After adding the above code the custom image banner will be shown in the Hot Sellers
!
There is one other way by which you can show field title and field value for particular
record. To achieve this you have to add. This block will help us to print both fields
parameters in just one call.
{{block class="Bricks\AdvanceFields\Block\Advancefields\Row"
name="advancefields_row" template="Bricks_AdvanceFields::advancefields/row.phtml"
field_id="1"}}
It will show the field title and field value in the list format.
!
To Show all the customer fields of the particular page then you have to call the below
block code in the page
{{block class="Bricks\AdvanceFields\Block\Advancefields\Listing"
name="advancefields_listing" template="Bricks_AdvanceFields::advancefields/
listing.phtml"}}
It will list out all the fields of that particular page in the list format.
If you like to enable listing fields by default on all the pages. Then you have to set the
Show Advanced Fields On CMS Pages to Yes. After setting it to Yes all the custom fields
will be listing on the corresponding pages.
Make sure cache flushed after making changes in the backend.
!
Below is the summary of all the block code available in the Bricks Advanced Field
Extension.
2. To Show Particular Field Title of the row
{{block class="Bricks\AdvanceFields\Block\Advancefields\Field"
name="advancefields_listing" template="Bricks_AdvanceFields::advancefields/
field.phtml" field_id="1" variable="field_title"}}
To Show Particular Field value of the row
{{block class="Bricks\AdvanceFields\Block\Advancefields\Field"
name="advancefields_listing" template="Bricks_AdvanceFields::advancefields/
field.phtml" field_id="2" variable="field_value"}}
To Show list of all the fields available for that particular page
{{block class="Bricks\AdvanceFields\Block\Advancefields\Listing"
name="advancefields_listing" template="Bricks_AdvanceFields::advancefields/
listing.phtml"}}
To Show title and value of particular row in one call
{{block class="Bricks\AdvanceFields\Block\Advancefields\Row"
name="advancefields_row" template="Bricks_AdvanceFields::advancefields/row.phtml"
field_id="2"}}
3. Direct Adding code in PHTML File
In case you can want to use the block code directly in the phtml template then you can
use below code to show the custom field:
<?php echo $this->getLayout()-
>createBlock(“Bricks\AdvanceFields\Block\Advancefields\Field")-
>getAdvanceFieldsValue(1,'field_title'); ?>
Above code will show Field title of 1 record. For Example I have added the custom block
code in the newsletter subscribe.phtml and title of the first record showing as below.
!
To show the value of the field
<?php echo $this->getLayout()-
>createBlock("Bricks\AdvanceFields\Block\Advancefields\Field")-
>getAdvanceFieldsValue(1,'field_value'); ?>